Ejemplo n.º 1
0
        internal IAsyncResult BeginConnect(int timeout,
                                           string server,
                                           int port,
                                           AsyncCallback cb,
                                           object state)
        {
            CheckDisposed();

            Connect_SO stateObj = null;

            if (null == server)
            {
                throw new ArgumentNullException("server");
            }

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("port", "Value, specified for the port is out of valid range.");
            }

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(timeout, cb, state);

                _socket.ConnectTimeout = timeout;
                _socket.BeginConnect(server, port,
                                     new AsyncCallback(this.OnEndConnectCB),
                                     stateObj);
            }
            catch (SocketException e)
            {
                SetProgress(false);
                CheckDisposed();
                CheckTimeoutException(e);
                throw;
            }
            catch (Exception)
            {
                SetProgress(false);
                CheckDisposed();
                throw;
            }
            catch
            {
                SetProgress(false);
                CheckDisposed();
                throw;
            }
            return(stateObj);
        }
Ejemplo n.º 2
0
 internal override IAsyncResult BeginEstablish(int timeout, AsyncCallback cb, object state)
 {
     CheckDisposed();
     try
     {
         _socket.ConnectTimeout = timeout;
         return(_socket.BeginConnect(_remoteEP, cb, state));
     }
     catch (SocketException e)
     {
         CheckDisposed();
         CheckTimeoutException(e);
         throw;
     }
     catch
     {
         CheckDisposed();
         throw;
     }
 }