diff --git a/src/client/spark_websocket/Core/WebsocketConnectionGateway.cs b/src/client/spark_websocket/Core/WebsocketConnectionGateway.cs
index fce4ce107..812da36db 100644
--- a/src/client/spark_websocket/Core/WebsocketConnectionGateway.cs
+++ b/src/client/spark_websocket/Core/WebsocketConnectionGateway.cs
@@ -49,7 +49,8 @@ namespace bts.websocket_core {
// class SocketsHandler {
// private WebApplication? app = null;
// private WebsocketServerParams? _server_params = null;
- // public void start_listening(WebsocketServerParams server_params) {
+
+ // public void start_listening(WebsocketServerParams server_params) {
// // start listening, assert that init has been called already
// bts.Log.assert(_server_params == null);
// bts.Log.assert(app == null);
@@ -74,6 +75,7 @@ namespace bts.websocket_core {
// }
+
// }
///
@@ -183,8 +185,34 @@ namespace bts.websocket_core {
/// 3. asks sync to handle disconnection
///
public void HandleDisconnection(WebsocketClientID id, string optional_message = "") {
- TryDisconnect(id, optional_message);
+ var log = GetLogger($"WebsocketGateway.HandleDisconnection tried closing client_id: {id} with message: {optional_message}");
+ var socket = Connections.GetSocket(id);
+ var que = Connections.GetSocketQueue(id);
+ if (socket == null || que == null) {
+ log(" failed as could not find socket in dictionary");
+ Sync.handle_disconnection(id);
+ return;
+ }
+ if (!IsSocketOpen(socket)) {
+ if (socket.CloseStatus == WebSocketCloseStatus.NormalClosure) {
+ log(" already closed properly by other thread");
+ return;
+ }
+ log(" already closed ");
+ Sync.handle_disconnection(id);
+ Connections.RemoveConnection(id);
+ return;
+ }
+ que.Enqueue(Tuple.Create(MessageType.Close, ""));
+ log(" added to que");
+ return;
}
+ ///
+ /// tries to send request to client to disconnect
+ ///
+ /// id of client to whom the Disconnect message should be sent
+ ///
+ /// task that completes if client disconnects or if there is an error
///
/// should be called after init
@@ -310,35 +338,7 @@ namespace bts.websocket_core {
} catch (OperationCanceledException) {//not sure about this read that this should just be ignored
}
}
- ///
- /// tries to send request to client to disconnect
- ///
- /// id of client to whom the Disconnect message should be sent
- ///
- /// task that completes if client disconnects or if there is an error
- public void TryDisconnect(WebsocketClientID id, string message) {
- var log = GetLogger($"WebsocketGateway.TryDisconnect tried closing client_id: {id} with message: {message}");
- var socket = Connections.GetSocket(id);
- var que = Connections.GetSocketQueue(id);
- if (socket == null || que == null) {
- log(" failed as could not find socket in dictionary");
- Sync.handle_disconnection(id);
- return;
- }
- if (!IsSocketOpen(socket)) {
- if (socket.CloseStatus == WebSocketCloseStatus.NormalClosure) {
- log(" already closed properly by other thread");
- return;
- }
- log(" already closed ");
- Sync.handle_disconnection(id);
- Connections.RemoveConnection(id);
- return;
- }
- que.Enqueue(Tuple.Create(MessageType.Close, ""));
- log(" added to que");
- return;
- }
+
public async Task SendDisconnectRequestAsync(WebsocketClientID id, string message) {
var log = GetLogger($"WebsocketGateway.SendDisconnectRequestAsync tried closing client_id: {id} with message: {message}");
var sckt = Connections.GetSocket(id);