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(); } }
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(); } }
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(); } }
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_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(); } }
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(); } }
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(); } }