Skip to content

Commit 70133fe

Browse files
committed
Merge branch 'po/fix-ws'
* po/fix-ws: Remove duplicate calls to On_Close and Shutdown. Make Shutdown_Signal atomic. Minor reformatting.
2 parents a2f6fc5 + 69a9eda commit 70133fe

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/core/aws-net-websocket-registry.adb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2012-2019, AdaCore --
4+
-- Copyright (C) 2012-2021, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -131,7 +131,7 @@ package body AWS.Net.WebSocket.Registry is
131131

132132
Message_Senders : Message_Sender_Set_Ref;
133133

134-
Shutdown_Signal : Boolean := False;
134+
Shutdown_Signal : Boolean := False with Atomic;
135135

136136
-- Concurrent access to Set above
137137

@@ -273,6 +273,7 @@ package body AWS.Net.WebSocket.Registry is
273273
DB.Remove (WS.Get);
274274
Message_Queue.Add (WS);
275275
end if;
276+
276277
K := K + 1;
277278
end loop;
278279
end;
@@ -370,7 +371,6 @@ package body AWS.Net.WebSocket.Registry is
370371
Do_Unregister (WS);
371372
WebSocket_Exception
372373
(WS, Exception_Message (E), Protocol_Error);
373-
WS.On_Close (Exception_Message (E));
374374
WS.Shutdown;
375375
end;
376376
end;
@@ -916,7 +916,6 @@ package body AWS.Net.WebSocket.Registry is
916916
(WS, Exception_Message (E), Protocol_Error);
917917

918918
WS.Close (Exception_Message (E), Going_Away);
919-
WS.On_Close (Exception_Message (E));
920919

921920
-- No more data to send from this socket
922921
Pending := 0;
@@ -976,7 +975,6 @@ package body AWS.Net.WebSocket.Registry is
976975
WebSocket_Exception
977976
(WebSocket, Exception_Message (E), Protocol_Error);
978977

979-
WebSocket.On_Close (Exception_Message (E));
980978
WebSocket.Close (Exception_Message (E), Going_Away);
981979
end;
982980

src/core/aws-net-websocket.adb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2012-2016, AdaCore --
4+
-- Copyright (C) 2012-2021, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -53,7 +53,8 @@ package body AWS.Net.WebSocket is
5353
end record;
5454

5555
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
56-
(AWS.Client.HTTP_Connection, AWS.Client.HTTP_Connection_Access);
56+
(AWS.Client.HTTP_Connection, AWS.Client.HTTP_Connection_Access);
57+
5758
procedure Unchecked_Free is new Unchecked_Deallocation
5859
(Net.WebSocket.Protocol.State'Class,
5960
Net.WebSocket.Protocol.State_Class);
@@ -91,12 +92,12 @@ package body AWS.Net.WebSocket is
9192
(Socket : in out Object'Class;
9293
URI : String)
9394
is
95+
URL : constant AWS.URL.Object := AWS.URL.Parse (URI);
9496
Headers : AWS.Headers.List := AWS.Headers.Empty_List;
9597
Resp : AWS.Response.Data;
96-
Protocol : AWS.Net.WebSocket.Protocol.State_Class;
97-
URL : constant AWS.URL.Object := AWS.URL.Parse (URI);
98+
Protocol : Net.WebSocket.Protocol.State_Class;
9899
begin
99-
-- Initially, the connection is initiated with standard http GET.
100+
-- Initially, the connection is initiated with standard http GET
100101

101102
Socket.Connection := new AWS.Client.HTTP_Connection;
102103
Protocol := new Net.WebSocket.Protocol.RFC6455.State;
@@ -406,7 +407,7 @@ package body AWS.Net.WebSocket is
406407
function Poll
407408
(Socket : in out Object'Class;
408409
Timeout : Duration)
409-
return Boolean
410+
return Boolean
410411
is
411412
procedure Do_Receive
412413
(Socket : Object'Class;
@@ -427,11 +428,10 @@ package body AWS.Net.WebSocket is
427428
end Do_Receive;
428429

429430
function Read_Message is new AWS.Net.WebSocket.Read_Message
430-
(Receive => Do_Receive);
431+
(Receive => Do_Receive);
431432

432433
Event : AWS.Net.Event_Set;
433-
Msg : Ada.Strings.Unbounded.Unbounded_String;
434-
434+
Msg : Unbounded_String;
435435
begin
436436
Event := Socket.Poll
437437
((AWS.Net.Input => True, others => False), Timeout => Timeout);
@@ -471,8 +471,8 @@ package body AWS.Net.WebSocket is
471471
------------------
472472

473473
function Read_Message
474-
(WebSocket : in out Object'Class;
475-
Message : in out Ada.Strings.Unbounded.Unbounded_String)
474+
(WebSocket : in out Object'Class;
475+
Message : in out Unbounded_String)
476476
return Boolean
477477
is
478478
Data : Stream_Element_Array (1 .. 4_096);

0 commit comments

Comments
 (0)