From 877ae47f3c835e89dd7bfc57c1aecb297b3540aa Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Sat, 2 Dec 2017 13:07:50 +0100 Subject: [PATCH 1/2] DoWrite changed from recursive function to loop --- src/core/Akka/IO/TcpConnection.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/Akka/IO/TcpConnection.cs b/src/core/Akka/IO/TcpConnection.cs index a52c148c5b6..f8f0562e101 100644 --- a/src/core/Akka/IO/TcpConnection.cs +++ b/src/core/Akka/IO/TcpConnection.cs @@ -830,7 +830,8 @@ public override PendingWrite DoWrite(ConnectionInfo info) { try { - PendingWrite WriteToChannel(ByteString data) + var data = _buffer; + while(true) { var bytesWritten = _connection.Socket.Send(data.Buffers); if (_connection.traceLogging) @@ -838,7 +839,7 @@ PendingWrite WriteToChannel(ByteString data) 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 +849,6 @@ PendingWrite WriteToChannel(ByteString data) } } - return WriteToChannel(_buffer); - } catch (SocketException e) { From dd173f39ab55f8f3aacf84af96fc33f463c79355 Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Sat, 2 Dec 2017 16:53:56 +0100 Subject: [PATCH 2/2] workaround for WSAEWOULDBLOCK --- src/core/Akka/IO/TcpConnection.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/core/Akka/IO/TcpConnection.cs b/src/core/Akka/IO/TcpConnection.cs index f8f0562e101..5b0a5f05b6b 100644 --- a/src/core/Akka/IO/TcpConnection.cs +++ b/src/core/Akka/IO/TcpConnection.cs @@ -833,7 +833,8 @@ public override PendingWrite DoWrite(ConnectionInfo info) 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) @@ -857,6 +858,26 @@ public override PendingWrite DoWrite(ConnectionInfo info) } } + 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() { } } }