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;
 }
        internal static ITcpConnection CreateConnectingConnection(ILogger log,
                                                                  Guid connectionId, 
                                                                  IPEndPoint remoteEndPoint,
                                                                  TcpClientConnector connector,
                                                                  TimeSpan connectionTimeout,
                                                                  Action<ITcpConnection> onConnectionEstablished,
                                                                  Action<ITcpConnection, SocketError> onConnectionFailed,
                                                                  Action<ITcpConnection, SocketError> onConnectionClosed)
        {
            var connection = new TcpConnection(log, connectionId, remoteEndPoint, onConnectionClosed);
// ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
                                  {
                                      connection.InitSocket(socket);
                                      if (onConnectionEstablished != null)
                                          onConnectionEstablished(connection);
                                  },
                                  (_, socketError) =>
                                  {
                                      if (onConnectionFailed != null)
                                          onConnectionFailed(connection, socketError);
                                  }, connection, connectionTimeout);
// ReSharper restore ImplicitlyCapturedClosure
            return connection;
        }
Esempio n. 3
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. 4
0
        internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint,
                                                                    TcpClientConnector connector,
                                                                    Action <TcpConnection> onConnectionEstablished,
                                                                    Action <TcpConnection, SocketError> onConnectionFailed)
        {
            var connection = new TcpConnection(remoteEndPoint);

            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
                connection.TrySend();
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            });
            return(connection);
        }
Esempio n. 5
0
        internal static ITcpConnection CreateConnectingConnection(ILogger log,
                                                                  Guid connectionId,
                                                                  IPEndPoint remoteEndPoint,
                                                                  TcpClientConnector connector,
                                                                  TimeSpan connectionTimeout,
                                                                  Action <ITcpConnection> onConnectionEstablished,
                                                                  Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                  Action <ITcpConnection, SocketError> onConnectionClosed)
        {
            var connection = new TcpConnectionLockless(log, connectionId, remoteEndPoint, onConnectionClosed);

// ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                if (connection.InitSocket(socket))
                {
                    if (onConnectionEstablished != null)
                    {
                        onConnectionEstablished(connection);
                    }
                    connection.StartReceive();
                    connection.TrySend();
                }
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
// ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
 internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint,
                                                                   TcpClientConnector connector,
                                                                   Action<TcpConnection> onConnectionEstablished,
                                                                   Action<TcpConnection, SocketError> onConnectionFailed)
 {
     var connection = new TcpConnection(remoteEndPoint);
     connector.InitConnect(remoteEndPoint,
                           (_, socket) =>
                           {
                               connection.InitSocket(socket);
                               if (onConnectionEstablished != null)
                                   onConnectionEstablished(connection);
                               connection.TrySend();
                           },
                           (_, socketError) =>
                           {
                               if (onConnectionFailed != null)
                                   onConnectionFailed(connection, socketError);
                           });
     return connection;
 }