Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }