Exemple #1
0
        void Bind_Read_End(IAsyncResult ar)
        {
            Bind_SO stateObj = (Bind_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int num = NStream.EndRead(ar);
                stateObj.ReadBytes += num;

                if (stateObj.ReadBytes < 8)
                {
                    //------------------------------------
                    // Read the response from proxy server.
                    //
                    NStream.BeginRead(_response,
                                      stateObj.ReadBytes,
                                      8 - stateObj.ReadBytes,
                                      new AsyncCallback(Bind_Read_End),
                                      stateObj);
                }
                else
                {
                    VerifyResponse();
                    _localEndPoint  = ConstructBindEndPoint(stateObj.ProxyIP);
                    _remoteEndPoint = null;
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
        private void Bind_Read_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                int num = base.NStream.EndRead(ar);
                asyncState.ReadBytes += num;
                if (asyncState.ReadBytes < 8)
                {
                    base.NStream.BeginRead(this._response, asyncState.ReadBytes, 8 - asyncState.ReadBytes, new AsyncCallback(this.Bind_Read_End), asyncState);
                }
                else
                {
                    this.VerifyResponse();
                    this._localEndPoint  = this.ConstructBindEndPoint(asyncState.ProxyIP);
                    this._remoteEndPoint = null;
                    asyncState.SetCompleted();
                }
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
Exemple #3
0
        void Bind_Connect_End(IAsyncResult ar)
        {
            Bind_SO stateObj = (Bind_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);

                //------------------------------------
                // Send CONNECT command
                //
                byte[] cmd = PrepareBindCmd(stateObj.BaseSocket);

                NStream.BeginWrite(cmd,
                                   0,
                                   cmd.Length,
                                   new AsyncCallback(Bind_Write_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
Exemple #4
0
        void Bind_GetHost_End(IAsyncResult ar)
        {
            Bind_SO stateObj = (Bind_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = EndGetHostByName(ar);
                if (host == null)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve proxy host name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(host, _proxyPort);
                stateObj.ProxyIP = proxyEndPoint.Address;

                //------------------------------------
                // Connect to proxy server
                //
                _socket.BeginConnect(proxyEndPoint,
                                     new AsyncCallback(Bind_Connect_End),
                                     stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
Exemple #5
0
        void Bind_Write_End(IAsyncResult ar)
        {
            Bind_SO stateObj = (Bind_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                NStream.EndWrite(ar);

                //------------------------------------
                // Read the response from proxy server.
                //
                NStream.BeginRead(
                    _response,
                    0,
                    8,
                    new AsyncCallback(Bind_Read_End),
                    stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
        private void Bind_Write_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base.NStream.EndWrite(ar);
                this.BeginReadVerifyReply(new AsyncCallback(this.Bind_Read_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
        private void Bind_Connect_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base._socket.EndConnect(ar);
                this.BeginNegotiate(new AsyncCallback(this.Bind_Negotiate_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
        private void Bind_Read_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                byte[] reply = this.EndReadVerifyReply(ar);
                this._localEndPoint  = this.ExtractReplyAddr(reply);
                this._remoteEndPoint = null;
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
            }
            asyncState.SetCompleted();
        }
        private void Bind_Negotiate_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                this.EndNegotiate(ar);
                byte[] buffer = this.PrepareBindCmd(asyncState.BaseSocket);
                base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Bind_Write_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
Exemple #10
0
        internal override IAsyncResult BeginBind(SocketBase baseSocket, AsyncCallback callback, object state)
        {
            base.CheckDisposed();
            Bind_SO d_so = new Bind_SO(callback, state);

            try
            {
                IPEndPoint localEndPoint = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint;
                localEndPoint.Port = 0;
                base._socket.Bind(localEndPoint);
            }
            catch (Exception exception)
            {
                d_so.Exception = exception;
            }
            d_so.SetCompleted();
            return(d_so);
        }
Exemple #11
0
        override internal IAsyncResult BeginBind(SocketBase baseSocket,
                                                 AsyncCallback callback,
                                                 object state)
        {
            CheckDisposed();
            Bind_SO stateObj = new Bind_SO(callback, state);

            try
            {
                IPEndPoint ep = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint;
                ep.Port = 0;
                _socket.Bind(ep);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            stateObj.SetCompleted();
            return(stateObj);
        }
        private void Bind_GetHost_End(IAsyncResult ar)
        {
            Bind_SO asyncState = (Bind_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                IPHostEntry host = SocketBase.EndGetHostByName(ar);
                if (host == null)
                {
                    throw new SocketException(0x2af9);
                }
                IPEndPoint remoteEP = SocketBase.ConstructEndPoint(host, base._proxyPort);
                asyncState.ProxyIP = remoteEP.Address;
                base._socket.BeginConnect(remoteEP, new AsyncCallback(this.Bind_Connect_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
		override internal IAsyncResult BeginBind(SocketBase baseSocket, 
			AsyncCallback callback, 
			object state)
		{
			CheckDisposed();
			Bind_SO stateObj = new Bind_SO(callback, state);
			try
			{
				IPEndPoint ep = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint;
				ep.Port = 0;
				_socket.Bind(ep);
			}
			catch(Exception e)
			{
				stateObj.Exception = e;
			}
			stateObj.SetCompleted();
			return stateObj;
		}