Skip to content

Commit

Permalink
Merge 5f626a9 into 45672e0
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzSpring committed Aug 18, 2023
2 parents 45672e0 + 5f626a9 commit 487b121
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/Fleck/WebSocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,28 @@ private void HandleReadError(Exception e)

private Task SendBytes(byte[] bytes, Action callback = null)
{
return Socket.Send(bytes, () =>
{
FleckLog.Debug("Sent " + bytes.Length + " bytes");
if (callback != null)
callback();
},
e =>
{
if (e is IOException)
FleckLog.Debug("Failed to send. Disconnecting.", e);
else
FleckLog.Info("Failed to send. Disconnecting.", e);
CloseSocket();
});
var tcs = new TaskCompletionSource<object>();

Socket.Send(bytes,
() =>
{
FleckLog.Debug("Sent " + bytes.Length + " bytes");
if (callback != null)
callback();
tcs.SetResult(null);
},
e =>
{
if (e is IOException)
FleckLog.Debug("Failed to send. Disconnecting.", e);
else
FleckLog.Info("Failed to send. Disconnecting.", e);
CloseSocket();
tcs.SetException(e);
}
);

return tcs.Task;
}

private void CloseSocket()
Expand Down

0 comments on commit 487b121

Please sign in to comment.