diff --git a/src/core/Akka/IO/TcpConnection.cs b/src/core/Akka/IO/TcpConnection.cs index a52c148c5b6..5b0a5f05b6b 100644 --- a/src/core/Akka/IO/TcpConnection.cs +++ b/src/core/Akka/IO/TcpConnection.cs @@ -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 { @@ -848,8 +850,6 @@ PendingWrite WriteToChannel(ByteString data) } } - return WriteToChannel(_buffer); - } catch (SocketException e) { @@ -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() { } } }