public static ITcpConnection CreateConnectingConnection(ILogger log,
                                                         Guid connectionId, 
                                                         IPEndPoint remoteEndPoint, 
                                                         string targetHost,
                                                         bool validateServer,
                                                         TcpClientConnector connector, 
                                                         TimeSpan connectionTimeout,
                                                         Action<ITcpConnection> onConnectionEstablished, 
                                                         Action<ITcpConnection, SocketError> onConnectionFailed,
                                                         Action<ITcpConnection, SocketError> onConnectionClosed)
 {
     var connection = new TcpConnectionSsl(log, connectionId, remoteEndPoint, onConnectionClosed);
     // ReSharper disable ImplicitlyCapturedClosure
     connector.InitConnect(remoteEndPoint,
                           (_, socket) =>
                           {
                               connection.InitClientSocket(socket, targetHost, validateServer);
                               if (onConnectionEstablished != null)
                                   ThreadPool.QueueUserWorkItem(o => onConnectionEstablished(connection));
                           },
                           (_, socketError) =>
                           {
                               if (onConnectionFailed != null)
                                   ThreadPool.QueueUserWorkItem(o => onConnectionFailed(connection, socketError));
                           }, connection, connectionTimeout);
     // ReSharper restore ImplicitlyCapturedClosure
     return connection;
 }
Esempio n. 2
0
        public static ITcpConnection CreateConnectingConnection(ILogger log,
                                                                Guid connectionId,
                                                                IPEndPoint remoteEndPoint,
                                                                string targetHost,
                                                                bool validateServer,
                                                                TcpClientConnector connector,
                                                                TimeSpan connectionTimeout,
                                                                Action <ITcpConnection> onConnectionEstablished,
                                                                Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                Action <ITcpConnection, SocketError> onConnectionClosed)
        {
            var connection = new TcpConnectionSsl(log, connectionId, remoteEndPoint, onConnectionClosed);

            // ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) => {
                connection.InitClientSocket(socket, targetHost, validateServer);
                if (onConnectionEstablished != null)
                {
                    ThreadPool.QueueUserWorkItem(o => onConnectionEstablished(connection));
                }
            },
                                  (_, socketError) => {
                if (onConnectionFailed != null)
                {
                    ThreadPool.QueueUserWorkItem(o => onConnectionFailed(connection, socketError));
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
Esempio n. 3
0
        public ITcpConnection ConnectTo(ILogger log,
                                        Guid connectionId,
                                        IPEndPoint remoteEndPoint,
                                        bool ssl,
                                        bool validateServer,
                                        TimeSpan timeout,
                                        Action <ITcpConnection> onConnectionEstablished         = null,
                                        Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                        Action <ITcpConnection, SocketError> onConnectionClosed = null)
        {
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            if (ssl)
            {
                return(TcpConnectionSsl.CreateConnectingConnection(
                           log, connectionId, remoteEndPoint, validateServer,
                           this, timeout, onConnectionEstablished, onConnectionFailed, onConnectionClosed));
            }

            return(TcpConnection.CreateConnectingConnection(
                       log, connectionId, remoteEndPoint, this, timeout,
                       onConnectionEstablished, onConnectionFailed, onConnectionClosed));
        }