Skip to content

Commit

Permalink
Akka.IO bug fixes (#3206)
Browse files Browse the repository at this point in the history
* DoWrite changed from recursive function to loop

* workaround for WSAEWOULDBLOCK
  • Loading branch information
Horusiath committed Dec 4, 2017
1 parent 87fc207 commit 5ddccc9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/core/Akka/IO/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,15 +830,17 @@ public override PendingWrite DoWrite(ConnectionInfo info)
{
try
{
PendingWrite WriteToChannel(ByteString data)
var data = _buffer;
while(true)
{
var bytesWritten = _connection.Socket.Send(data.Buffers);
var bytesWritten = Send(data);

if (_connection.traceLogging)
_connection.Log.Debug("Wrote [{0}] bytes to channel", bytesWritten);
if (bytesWritten < data.Count)
{
// we weren't able to write all bytes from the buffer, so we need to try again later
return WriteToChannel(data.Slice(bytesWritten));
data = data.Slice(bytesWritten);
}
else // finished writing
{
Expand All @@ -848,8 +850,6 @@ PendingWrite WriteToChannel(ByteString data)
}
}

return WriteToChannel(_buffer);

}
catch (SocketException e)
{
Expand All @@ -858,6 +858,26 @@ PendingWrite WriteToChannel(ByteString data)
}
}

private int Send(ByteString data)
{
try
{
return _connection.Socket.Send(data.Buffers);
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.WouldBlock)
{
try
{
_connection.Socket.Blocking = true;
return _connection.Socket.Send(data.Buffers);
}
finally
{
_connection.Socket.Blocking = false;
}
}
}

public override void Release() { }
}
}
Expand Down

0 comments on commit 5ddccc9

Please sign in to comment.