void Connect_GetHost_Host_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); IPHostEntry host = EndGetHostByName(ar); if (null == host) { throw new SocketException(SockErrors.WSAHOST_NOT_FOUND); } //throw new HostNotFoundException("Unable to resolve host name."); stateObj.RemoteEndPoint = SocketBase.ConstructEndPoint(host, stateObj.Port); //------------------------------------ // Get end point for the proxy server // BeginGetHostByName(_proxyServer, new AsyncCallback(this.Connect_GetHost_Proxy_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void Connect_Connect_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); _socket.EndConnect(ar); _localEndPoint = null; _remoteEndPoint = stateObj.RemoteEndPoint; //------------------------------------ // Send CONNECT command // byte[] cmd = PrepareConnectCmd(stateObj.RemoteEndPoint); NStream.BeginWrite(cmd, 0, cmd.Length, new AsyncCallback(Connect_Write_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void Connect_GetHost_Host_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); IPHostEntry host = EndGetHostByName(ar); if (null != host) { stateObj.RemoteEndPoint = ConstructEndPoint(host, stateObj.HostPort); } //------------------------------------ // Get end point for the proxy server // BeginGetHostByName(_proxyServer, new AsyncCallback(Connect_GetHost_Proxy_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void Connect_Write_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); NStream.EndWrite(ar); //------------------------------------ // Read the response from proxy server. // NStream.BeginRead( _response, 0, 8, new AsyncCallback(Connect_Read_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void GetHost_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); IPHostEntry host = Dns.EndGetHostByName(ar); if (null == host) { throw new SocketException(SockErrors.WSAHOST_NOT_FOUND); } //throw new HostNotFoundException("Unable to resolve host name."); EndPoint remoteEP = SocketBase.ConstructEndPoint(host, stateObj.Port); _socket.BeginConnect(remoteEP, new AsyncCallback(Connect_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
private void Connect_Read_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_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.Connect_Read_End), asyncState); } else { this.VerifyResponse(); if (asyncState.RemoteEndPoint == null) { this._remotePort = asyncState.HostPort; this._remoteHost = asyncState.HostName; } asyncState.SetCompleted(); } } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
private void Connect_ReadReply_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); ByteVector reply = this.EndReadReply(ar); string reason = null; int num = this.AnalyzeReply(reply, out reason); if ((num < 200) || (num > 0x12b)) { if (((0x197 != num) || asyncState.UseCredentials) || (base._proxyUser == null)) { throw new SocketException(0x274d); } asyncState.UseCredentials = true; byte[] buffer = this.GetConnectCmd(asyncState.HostName, asyncState.HostPort, asyncState.UseCredentials); base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState); } else { asyncState.SetCompleted(); } } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
void Connect_Read_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_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(Connect_Read_End), stateObj); } else { VerifyResponse(); stateObj.SetCompleted(); } } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void Connect_ReadReply_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); ByteVector reply = EndReadReply(ar); //------------------------------------------ // Analyze reply string reason = null; int code = AnalyzeReply(reply, out reason); //------------------------------------------ // is good return code? if (code >= 200 && code <= 299) { stateObj.SetCompleted(); } else if ((407 == code) && !(stateObj.UseCredentials) && (_proxyUser != null)) { //------------------------------------------ // If Proxy Authentication Required // but we do not issued it, then try again stateObj.UseCredentials = true; //------------------------------------------ // Send CONNECT command byte[] cmd = GetConnectCmd( stateObj.HostName, stateObj.HostPort, stateObj.UseCredentials); NStream.BeginWrite(cmd, 0, cmd.Length, new AsyncCallback(Connect_Write_End), stateObj); } else { // string msg = string.Format("Connection refused by web proxy: {0} ({1}).", reason, code); // throw new ProxyErrorException(msg); throw new SocketException(SockErrors.WSAECONNREFUSED); } } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
private void Connect_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); base._socket.EndConnect(ar); } catch (Exception exception) { asyncState.Exception = exception; } asyncState.SetCompleted(); }
void Connect_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); _socket.EndConnect(ar); } catch (Exception e) { stateObj.Exception = e; } stateObj.SetCompleted(); }
private void Connect_Connect_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); base._socket.EndConnect(ar); this.BeginNegotiate(new AsyncCallback(this.Connect_Negotiate_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
private void Connect_Negotiate_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); this.EndNegotiate(ar); byte[] buffer = this.PrepareConnectCmd(asyncState.RemoteEndPoint, asyncState.HostName, asyncState.HostPort); base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
private void Connect_Connect_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); base._socket.EndConnect(ar); byte[] buffer = this.GetConnectCmd(asyncState.HostName, asyncState.HostPort, asyncState.UseCredentials); base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
void Connect_Read_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_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(Connect_Read_End), stateObj); } else { VerifyResponse(); //--------------------------------------- // I we unable to resolve remote host then // store information - it will required // later for BIND command. if (null == stateObj.RemoteEndPoint) { _remotePort = stateObj.HostPort; _remoteHost = stateObj.HostName; } stateObj.SetCompleted(); } } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
private void Connect_Connect_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); base._socket.EndConnect(ar); this._localEndPoint = null; this._remoteEndPoint = asyncState.RemoteEndPoint; byte[] buffer = this.PrepareConnectCmd(asyncState.RemoteEndPoint); base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
private void Connect_GetHost_Host_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_SO)ar.AsyncState; try { asyncState.UpdateContext(); IPHostEntry host = SocketBase.EndGetHostByName(ar); if (host != null) { asyncState.RemoteEndPoint = SocketBase.ConstructEndPoint(host, asyncState.HostPort); } SocketBase.BeginGetHostByName(base._proxyServer, new AsyncCallback(this.Connect_GetHost_Proxy_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }
private void Connect_GetHost_Proxy_End(IAsyncResult ar) { Connect_SO asyncState = (Connect_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); base._socket.BeginConnect(remoteEP, new AsyncCallback(this.Connect_Connect_End), asyncState); } catch (Exception exception) { asyncState.Exception = exception; asyncState.SetCompleted(); } }