/// <summary>
        /// Connect callback!
        /// </summary>
        /// <param name="ar"></param>
        internal void BeginConnectCallbackAsync(object sender, SocketAsyncEventArgs e)
        {
            if (!Disposed)
            {
                BaseSocketConnection connection = null;
                SocketConnector      connector  = null;
                Exception            exception  = null;

                if (e.SocketError == SocketError.Success)
                {
                    try
                    {
                        connector = (SocketConnector)e.UserToken;

                        connection = new ClientSocketConnection(Host, connector, connector.Socket);

                        //----- Adjust buffer size!
                        connector.Socket.ReceiveBufferSize = Host.SocketBufferSize;
                        connector.Socket.SendBufferSize    = Host.SocketBufferSize;

                        //----- Initialize!
                        Host.AddSocketConnection(connection);
                        connection.Active = true;

                        Host.InitializeConnection(connection);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;

                        if (connection != null)
                        {
                            Host.DisposeConnection(connection);
                            Host.RemoveSocketConnection(connection);

                            connection = null;
                        }
                    }
                }
                else
                {
                    exception = new SocketException((int)e.SocketError);
                }

                if (exception != null)
                {
                    FReconnectAttempted++;
                    ReconnectConnection(false, exception);
                }
            }

            e.UserToken = null;
            e.Dispose();
            e = null;
        }
Beispiel #2
0
        /// <summary>
        /// Reconnects the connection adjusting the reconnect timer.
        /// </summary>
        /// <param name="connection">
        /// Connection.
        /// </param>
        /// <param name="sleepTimeOutValue">
        /// Sleep timeout before reconnect.
        /// </param>
        internal override void BeginReconnect(ClientSocketConnection connection)
        {
            if (!Disposed)
            {
                SocketConnector connector = (SocketConnector)connection.Creator;

                if ((connector.ProxyInfo == null || connector.ProxyInfo.Completed))
                {
                    connector.Reconnect(true, null, null);
                }
            }
        }
        /// <summary>
        /// Reconnects the connection adjusting the reconnect timer.
        /// </summary>
        /// <param name="connection">
        /// Connection.
        /// </param>
        /// <param name="sleepTimeOutValue">
        /// Sleep timeout before reconnect.
        /// </param>
        internal override void BeginReconnect(ClientSocketConnection connection)
        {
            if (!Disposed)
            {
                if (connection != null)
                {
                    SocketConnector connector = (SocketConnector)connection.Creator;

                    if (connector != null)
                    {
                        connector.ReconnectConnection(true, null);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Connect callback!
        /// </summary>
        /// <param name="ar"></param>
        internal void BeginConnectCallback(IAsyncResult ar)
        {
            if (!Disposed)
            {
                BaseSocketConnection connection = null;
                SocketConnector      connector  = null;

                try
                {
                    connector  = (SocketConnector)ar.AsyncState;
                    connection = new ClientSocketConnection(Host, connector, connector.Socket);

                    connector.Socket.EndConnect(ar);

                    //----- Adjust buffer size!
                    connector.Socket.ReceiveBufferSize = Host.SocketBufferSize;
                    connector.Socket.SendBufferSize    = Host.SocketBufferSize;

                    connection.Active = true;

                    //----- Initialize!
                    Host.AddSocketConnection(connection);
                    InitializeConnection(connection);
                }
                catch (Exception ex)
                {
                    if (ex is SocketException)
                    {
                        FReconnectAttempted++;
                        Reconnect(false, connection, ex);
                    }
                    else
                    {
                        Host.FireOnException(connection, ex);
                    }
                }
            }
        }
 internal abstract void BeginReconnect(ClientSocketConnection connection);
 internal override void BeginReconnect(ClientSocketConnection connection)
 {
 }
Beispiel #7
0
        /// <summary>
        /// Reconnects the connection adjusting the reconnect timer.
        /// </summary>
        /// <param name="connection">
        /// Connection.
        /// </param>
        /// <param name="sleepTimeOutValue">
        /// Sleep timeout before reconnect.
        /// </param>
        internal override void BeginReconnect(ClientSocketConnection connection)
        {
            
            if (!Disposed)
            {

              SocketConnector connector = (SocketConnector) connection.Creator;

              if ( (connector.ProxyInfo == null || connector.ProxyInfo.Completed) )
              {
                connector.Reconnect(true, null, null);
              }

            }

        }
Beispiel #8
0
        /// <summary>
        /// Connect callback!
        /// </summary>
        /// <param name="ar"></param>
        internal void BeginConnectCallback(IAsyncResult ar)
        {

            if (!Disposed)
            {

                BaseSocketConnection connection = null;
                SocketConnector connector = null;

                try
                {

                  connector = (SocketConnector) ar.AsyncState;
                  connection = new ClientSocketConnection(Host, connector, connector.Socket);

                  connector.Socket.EndConnect(ar);

                  //----- Adjust buffer size!
                  connector.Socket.ReceiveBufferSize = Host.SocketBufferSize;
                  connector.Socket.SendBufferSize = Host.SocketBufferSize;
                  
                  connection.Active = true;

                  //----- Initialize!
                  Host.AddSocketConnection(connection);
                  InitializeConnection(connection);

                }
                catch (Exception ex)
                {

                    if (ex is SocketException)
                    {

                      FReconnectAttempted++;
                      Reconnect(false, connection, ex);

                    }
                    else
                    {
                      Host.FireOnException(connection, ex);
                    }

                }

            }

        }
Beispiel #9
0
 internal override void BeginReconnect(ClientSocketConnection connection) { }
 internal abstract void BeginReconnect(ClientSocketConnection connection);