WebSocket: Close after IOException

master
Harald Wolff 2019-09-02 12:18:35 +02:00
parent 752b36037a
commit 0175870be6
1 changed files with 19 additions and 1 deletions

View File

@ -146,6 +146,11 @@ namespace ln.http.websocket
break;
}
}
} catch (IOException)
{
State = WebSocketState.ERROR;
Logging.Log(LogLevel.DEBUG, "WebSocket connection was dropped unexpected");
Close();
} catch (Exception e)
{
Logging.Log(LogLevel.ERROR, "WebSocket caught Exception: {0}", e.ToString());
@ -160,7 +165,20 @@ namespace ln.http.websocket
lock (Stream)
{
if (State == WebSocketState.OPEN)
frame.WriteTo(Stream);
{
try
{
frame.WriteTo(Stream);
} catch (IOException)
{
if (State != WebSocketState.ERROR)
{
Logging.Log(LogLevel.ERROR, "WebSocket.Send(): Websocket connection was dropped unexpected");
State = WebSocketState.ERROR;
Close();
}
}
}
else
throw new IOException("WebSocket is not open");
}