public void OutCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); if (socketError == SocketError.ConnectionRefused || socketError == SocketError.TimedOut || socketError == SocketError.ConnectionAborted || socketError == SocketError.HostUnreachable || socketError == SocketError.NetworkUnreachable || socketError == SocketError.NetworkDown) { AddReconnectTimer(); } else { throw NetMQException.Create(socketError); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; m_s.NoDelay = true; if (m_options.TcpKeepalive != -1) { m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connector down. Terminate(); } }
public void InCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { if (socketError == SocketError.ConnectionReset || socketError == SocketError.NoBufferSpaceAvailable || socketError == SocketError.TooManyOpenSockets) { m_socket.EventAcceptFailed(m_endpoint, ErrorHelper.SocketErrorToErrorCode(socketError)); Accept(); } else { m_acceptedSocket.Dispose(); NetMQException exception = NetMQException.Create(socketError); m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode); throw exception; } } else { // TODO: check TcpFilters m_acceptedSocket.NoDelay = true; // Utils.TuneTcpKeepalives(m_acceptedSocket, m_options.TcpKeepalive, m_options.TcpKeepaliveCnt, m_options.TcpKeepaliveIdle, m_options.TcpKeepaliveIntvl); // Create the engine object for this connection. StreamEngine engine = new StreamEngine(m_acceptedSocket, m_options, m_endpoint); // Choose I/O thread to run connecter in. Given that we are already // running in an I/O thread, there must be at least one available. IOThread ioThread = ChooseIOThread(m_options.Affinity); // Create and launch a session object. // TODO: send null in address parameter, is unneed in this case SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint)); session.IncSeqnum(); LaunchChild(session); SendAttach(session, engine, false); m_socket.EventAccepted(m_endpoint, m_acceptedSocket); Accept(); } }
public void OutCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); if (socketError == SocketError.ConnectionRefused || socketError == SocketError.TimedOut || socketError == SocketError.ConnectionAborted || socketError == SocketError.HostUnreachable || socketError == SocketError.NetworkUnreachable || socketError == SocketError.NetworkDown) { AddReconnectTimer(); } else { throw NetMQException.Create(socketError); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; m_s.NoDelay = true; //Utils.TuneTcpKeepalives(m_s, m_options.TcpKeepalive, m_options.TcpKeepaliveCnt, m_options.TcpKeepaliveIdle, m_options.TcpKeepaliveIntvl); // Create the engine object for this connection. StreamEngine engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connecter down. Terminate(); } }
public void InCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { if (socketError == SocketError.ConnectionReset || socketError == SocketError.NoBufferSpaceAvailable || socketError == SocketError.TooManyOpenSockets) { m_socket.EventAcceptFailed(m_endpoint, ErrorHelper.SocketErrorToErrorCode(socketError)); Accept(); } else { m_acceptedSocket.Dispose(); NetMQException exception = NetMQException.Create(socketError); m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode); throw exception; } } else { // TODO: check TcpFilters m_acceptedSocket.NoDelay = true; if (m_options.TcpKeepalive != -1) { m_acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { ByteArraySegment bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. StreamEngine engine = new StreamEngine(m_acceptedSocket, m_options, m_endpoint); // Choose I/O thread to run connecter in. Given that we are already // running in an I/O thread, there must be at least one available. IOThread ioThread = ChooseIOThread(m_options.Affinity); // Create and launch a session object. // TODO: send null in address parameter, is unneed in this case SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint)); session.IncSeqnum(); LaunchChild(session); SendAttach(session, engine, false); m_socket.EventAccepted(m_endpoint, m_acceptedSocket); Accept(); } }
/// <summary> /// This method is called when a message Send operation has been completed. /// </summary> /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param> /// <param name="bytesTransferred">the number of bytes that were transferred</param> /// <exception cref="NetMQException">A non-recoverable socket error occurred.</exception> /// <exception cref="NetMQException">If the socketError is not Success then it must be a valid recoverable error.</exception> public void OutCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); // Try again to connect after a time, // as long as the error is one of these.. if (socketError == SocketError.ConnectionRefused || socketError == SocketError.TimedOut || socketError == SocketError.ConnectionAborted || socketError == SocketError.HostUnreachable || socketError == SocketError.NetworkUnreachable || socketError == SocketError.NetworkDown || socketError == SocketError.AccessDenied) { AddReconnectTimer(); } else { throw NetMQException.Create(socketError); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; m_s.NoDelay = true; // As long as the TCP keep-alive option is not -1 (indicating no change), if (m_options.TcpKeepalive != -1) { // Set the TCP keep-alive option values to the underlying socket. m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { // Write the TCP keep-alive options to a byte-array, to feed to the IOControl method.. var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connector down. Terminate(); } }
/// <summary> /// This method is called when a message Send operation has been completed. /// </summary> /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param> /// <param name="bytesTransferred">the number of bytes that were transferred</param> /// <exception cref="NetMQException">A non-recoverable socket error occurred.</exception> /// <exception cref="NetMQException">If the socketError is not Success then it must be a valid recoverable error.</exception> public void OutCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); // Try again to connect after a time, // as long as the error is one of these.. if (socketError == SocketError.ConnectionRefused || socketError == SocketError.TimedOut || socketError == SocketError.ConnectionAborted || socketError == SocketError.HostUnreachable || socketError == SocketError.NetworkUnreachable || socketError == SocketError.NetworkDown || socketError == SocketError.AccessDenied) { if (m_options.ReconnectIvl >= 0) { AddReconnectTimer(); } } else { throw NetMQException.Create(socketError); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; m_s.NoDelay = true; // As long as the TCP keep-alive option is not -1 (indicating no change), if (m_options.TcpKeepalive != -1) { // Set the TCP keep-alive option values to the underlying socket. m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { // Write the TCP keep-alive options to a byte-array, to feed to the IOControl method.. var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connector down. Terminate(); } }
/// <summary> /// This is called when socket input has been completed. /// </summary> /// <param name="socketError">This indicates the status of the input operation - whether Success or some error.</param> /// <param name="bytesTransferred">the number of bytes that were transferred</param> /// <exception cref="NetMQException">A non-recoverable socket-error occurred.</exception> public void InCompleted(SocketError socketError, int bytesTransferred) { switch (socketError) { case SocketError.Success: { // TODO: check TcpFilters m_acceptedSocket.NoDelay = true; if (m_options.TcpKeepalive != -1) { m_acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_acceptedSocket, m_options, m_endpoint); // Choose I/O thread to run connector in. Given that we are already // running in an I/O thread, there must be at least one available. IOThread ioThread = ChooseIOThread(m_options.Affinity); // Create and launch a session object. // TODO: send null in address parameter, is unneeded in this case SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint)); session.IncSeqnum(); LaunchChild(session); SendAttach(session, engine, false); m_socket.EventAccepted(m_endpoint, m_acceptedSocket); Accept(); break; } case SocketError.ConnectionReset: case SocketError.NoBufferSpaceAvailable: case SocketError.TooManyOpenSockets: { m_acceptedSocket.Dispose(); m_socket.EventAcceptFailed(m_endpoint, socketError.ToErrorCode()); Accept(); break; } default: { m_acceptedSocket.Dispose(); NetMQException exception = NetMQException.Create(socketError); m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode); throw exception; } } }
/// <summary> /// /// </summary> /// <param name="socketError"></param> /// <param name="bytesTransferred"></param> /// <exception cref="NetMQException">a non-recoverable socket error occurred.</exception> public void OutCompleted(SocketError socketError, int bytesTransferred) { if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); if (socketError == SocketError.ConnectionRefused || socketError == SocketError.TimedOut || socketError == SocketError.ConnectionAborted || socketError == SocketError.HostUnreachable || socketError == SocketError.NetworkUnreachable || socketError == SocketError.NetworkDown) { AddReconnectTimer(); } else { throw NetMQException.Create(socketError); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; m_s.NoDelay = true; if (m_options.TcpKeepalive != -1) { m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connector down. Terminate(); } }
/// <summary> /// This method is called when a message Send operation has been completed. /// </summary> /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param> /// <param name="bytesTransferred">the number of bytes that were transferred</param> /// <exception cref="NetMQException">A non-recoverable socket error occurred.</exception> /// <exception cref="NetMQException">If the socketError is not Success then it must be a valid recoverable error.</exception> public void OutCompleted(SocketError socketError, int bytesTransferred) { Assumes.NotNull(m_s); if (socketError != SocketError.Success) { m_ioObject.RemoveSocket(m_s); m_handleValid = false; Close(); // Try again to connect after a time, if (m_options.ReconnectIvl >= 0) { AddReconnectTimer(); } } else { m_ioObject.RemoveSocket(m_s); m_handleValid = false; try { if (!m_s.NoDelay) { m_s.NoDelay = true; } } catch (ArgumentException) { // OSX sometime fail 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) { // Set the TCP keep-alive option values to the underlying socket. m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) { // Write the TCP keep-alive options to a byte-array, to feed to the IOControl method.. var bytes = new ByteArraySegment(new byte[12]); Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big; bytes.PutInteger(endian, m_options.TcpKeepalive, 0); bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4); bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8); m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); } } // Create the engine object for this connection. var engine = new StreamEngine(m_s, m_options, m_endpoint); m_socket.EventConnected(m_endpoint, m_s); m_s = null; // Attach the engine to the corresponding session object. SendAttach(m_session, engine); // Shut the connector down. Terminate(); } }