diff --git a/src/NetMQ/Core/Transports/Tcp/TcpConnector.cs b/src/NetMQ/Core/Transports/Tcp/TcpConnector.cs index fb22572f..e536cb6d 100755 --- a/src/NetMQ/Core/Transports/Tcp/TcpConnector.cs +++ b/src/NetMQ/Core/Transports/Tcp/TcpConnector.cs @@ -236,11 +236,18 @@ public void OutCompleted(SocketError socketError, int bytesTransferred) m_ioObject.RemoveSocket(m_s); m_handleValid = false; - try { + try + { m_s.NoDelay = true; - } catch (ArgumentException) { + } + catch (ArgumentException) + { // OSX sometime fail while the socket is still connecting } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.InvalidArgument) + { + // macOS may report EINVAL here while the socket is still connecting. + } // As long as the TCP keep-alive option is not -1 (indicating no change), if (m_options.TcpKeepalive != -1)