|
1 | 1 | ------------------------------------------------------------------------------ |
2 | 2 | -- Ada Web Server -- |
3 | 3 | -- -- |
4 | | --- Copyright (C) 2012-2019, AdaCore -- |
| 4 | +-- Copyright (C) 2012-2021, AdaCore -- |
5 | 5 | -- -- |
6 | 6 | -- This library is free software; you can redistribute it and/or modify -- |
7 | 7 | -- it under terms of the GNU General Public License as published by the -- |
@@ -161,10 +161,14 @@ package body AWS.Net.WebSocket.Registry is |
161 | 161 | entry Get_Socket (WebSocket : out Object_Class); |
162 | 162 | -- Get a WebSocket having some data to be sent |
163 | 163 |
|
164 | | - procedure Release_Socket (WebSocket : Object_Class); |
| 164 | + procedure Release_Socket (WebSocket : in out Object_Class); |
165 | 165 | -- Release a socket retrieved with Get_Socket above, this socket will be |
166 | 166 | -- then available again. |
167 | 167 |
|
| 168 | + procedure Free (WebSocket : in out Object_Class); |
| 169 | + -- Free WebSocket immediately if not taken by another task, otherwise |
| 170 | + -- record it to be freed as soon as it is released. |
| 171 | + |
168 | 172 | entry Not_Empty; |
169 | 173 | -- Returns if the Set is not empty |
170 | 174 |
|
@@ -329,7 +333,7 @@ package body AWS.Net.WebSocket.Registry is |
329 | 333 |
|
330 | 334 | procedure Do_Free (WebSocket : in out Object_Class) is |
331 | 335 | begin |
332 | | - Unchecked_Free (WebSocket); |
| 336 | + DB.Free (WebSocket); |
333 | 337 | end Do_Free; |
334 | 338 |
|
335 | 339 | ----------------- |
@@ -568,6 +572,24 @@ package body AWS.Net.WebSocket.Registry is |
568 | 572 | Registered.Clear; |
569 | 573 | end Finalize; |
570 | 574 |
|
| 575 | + ---------- |
| 576 | + -- Free -- |
| 577 | + ---------- |
| 578 | + |
| 579 | + procedure Free (WebSocket : in out Object_Class) is |
| 580 | + begin |
| 581 | + -- If WebSocket is in Sending it means that it has been |
| 582 | + -- taken by the Get_Socket call. We cannot free it now, we |
| 583 | + -- record this socket to be freed as soon as it is released |
| 584 | + -- (Release_Socket) call. |
| 585 | + |
| 586 | + if Sending.Contains (WebSocket.Id) then |
| 587 | + WebSocket.To_Free := True; |
| 588 | + else |
| 589 | + Unchecked_Free (WebSocket); |
| 590 | + end if; |
| 591 | + end Free; |
| 592 | + |
571 | 593 | ---------------- |
572 | 594 | -- Get_Socket -- |
573 | 595 | ---------------- |
@@ -738,10 +760,19 @@ package body AWS.Net.WebSocket.Registry is |
738 | 760 | -- Release_Socket -- |
739 | 761 | -------------------- |
740 | 762 |
|
741 | | - procedure Release_Socket (WebSocket : Object_Class) is |
| 763 | + procedure Release_Socket (WebSocket : in out Object_Class) is |
742 | 764 | begin |
743 | 765 | Sending.Exclude (WebSocket.Id); |
744 | | - New_Pending := True; |
| 766 | + |
| 767 | + -- The socket has been recorded to be freed. It is not anymore |
| 768 | + -- in the registry, we just need to free it now that it has |
| 769 | + -- been released. |
| 770 | + |
| 771 | + if WebSocket.To_Free then |
| 772 | + Unchecked_Free (WebSocket); |
| 773 | + else |
| 774 | + New_Pending := True; |
| 775 | + end if; |
745 | 776 | end Release_Socket; |
746 | 777 |
|
747 | 778 | ------------ |
|
0 commit comments