On 08/04/2018 11:10 AM, Jeffrey R. Carter wrote:
> 
> With GNAT, which we have to use because Gnoga's in Ada 12, you can include
> potentially blocking operations in a PO, which is nice, because that 
> restriction
> was a mistake. So I see no problem with putting these loops into protected
> operations. Modifying the Ping loop to create a structure of IDs to delete 
> after
> the ping loop should be trivial.

I've made the modification for Stop, which compiles fine:

diff --git a/src/gnoga-server-connection.adb b/src/gnoga-server-connection.adb
index da900782..4fe0fcd9 100644
--- a/src/gnoga-server-connection.adb
+++ b/src/gnoga-server-connection.adb
@@ -894,6 +894,9 @@ package body Gnoga.Server.Connection is
       procedure Delete_All_Connections;
       --  Called by Stop to close down server

+      procedure Close_All;
+      --  Closes all connections
+
       function Active_Connections return Ada.Containers.Count_Type;
       --  Returns the number of active connections
    private
@@ -1101,6 +1104,31 @@ package body Gnoga.Server.Connection is
          end loop;
       end Delete_All_Connections;

+      procedure Close_All is
+         procedure Close (C : Socket_Maps.Cursor);
+
+         procedure Close (C : Socket_Maps.Cursor) is
+            ID      : constant Gnoga.Types.Connection_ID := Socket_Maps.Key 
(C);
+            Socket  : constant Socket_Type               := Socket_Map.Element
(ID);
+         begin -- Close
+            if Socket.Content.Connection_Type = Long_Polling then
+               Socket.Content.Finalized := True;
+            else
+               Execute_Script (ID, "ws.close()");
+            end if;
+         exception -- Close
+            when E : others =>
+               Log ("Error Connection_Manager.Close_All.Close - " & ID'Img);
+               Log (Ada.Exceptions.Exception_Information (E));
+         end Close;
+      begin -- Close_All
+         All_Connections : loop
+            exit All_Connections when Socket_Map.Is_Empty;
+
+            Close (C => Socket_Map.First);
+         end loop All_Connections;
+      end Close_All;
+
       function Active_Connections return Ada.Containers.Count_Type is
       begin
          return Socket_Map.Length;
@@ -2306,7 +2334,6 @@ package body Gnoga.Server.Connection is
    ----------

    procedure Stop is
-      ID : Gnoga.Types.Connection_ID;
    begin
       if not Exit_Application_Requested and
         Watchdog /= null and
@@ -2316,12 +2343,7 @@ package body Gnoga.Server.Connection is
          Watchdog.Stop;
          Watchdog := null;

-         Connection_Manager.First (ID);
-         while ID /= 0 loop
-            Close (ID);
-            Connection_Manager.Next (ID);
-         end loop;
-
+         Connection_Manager.Close_All;
          Connection_Manager.Delete_All_Connections;

          Gnoga_HTTP_Server.Stop;

If people use this for a while without problems, we might want to make it
permanent and try something similar for Ping.

-- 
Jeff Carter
"The time has come to act, and act fast. I'm leaving."
Blazing Saddles
36

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gnoga-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gnoga-list

Reply via email to