internal protected virtual void TriggerOnHttpRequest(Connection connection, AsyncHttpContext context) { if (this.OnHttpRequest != null) { OnAsyncHttpRequestArgs lEventArgs = new OnAsyncHttpRequestArgs(connection, context); this.OnHttpRequest(this, lEventArgs); } }
protected override void DoSetup() { this.DataConnection.MaxLineLength = 8096; this.DataConnection.MaxLineLengthEnabled = true; this.DataConnection.AsyncDisconnect += new EventHandler(cbDisconnect); this.fContext = ((AsyncHttpServer)Owner).NewContext(this); try { this.DataConnection.BeginReadLine(new AsyncCallback(HeaderFirstLineCallback), null); } catch (SocketException) { } catch (ObjectDisposedException) { } }
public override void Setup() { this.DataConnection.MaxLineLength = 8096; this.DataConnection.MaxLineLengthEnabled = true; this.DataConnection.AsyncDisconnect += DisconnectCallback; this.fContext = this.fOwner.NewContext(this); try { this.DataConnection.BeginReadLine(HeaderFirstLineCallback, null); } catch (SocketException) { Done(); } catch (ObjectDisposedException) { Done(); } }
private void ResponseBodyCallback(IAsyncResult ar) { try { DataConnection.EndWrite(ar); if (ar.AsyncState is Stream) { Stream lData = (Stream)ar.AsyncState; Int32 lLen = lData.Read(fBodyBuffer, 0, fBodyBuffer.Length); if (lLen != 0) { DataConnection.BeginWrite(fBodyBuffer, 0, lLen, ResponseBodyCallback, lData); return; } } else if (ar.AsyncState is Byte[]) { Byte[] lData = (Byte[])ar.AsyncState; Int32 lLen = fBodyBuffer.Length; if (fBodyOffset + lLen > lData.Length) { lLen = lData.Length - fBodyOffset; } if (lLen != 0) { Array.Copy(lData, fBodyOffset, fBodyBuffer, 0, lLen); fBodyOffset += lLen; DataConnection.BeginWrite(fBodyBuffer, 0, lLen, ResponseBodyCallback, lData); return; } } } catch (ConnectionClosedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (SocketException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (ObjectDisposedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } //AsyncHttpContext lOldContext = fContext; fContext = this.fOwner.NewContext(this); try { DataConnection.BeginReadLine(HeaderFirstLineCallback, null); } catch (SocketException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (ObjectDisposedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } this.fOwner.TriggerHttpResponseSent(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); }
public AsyncHttpRequestEventArgs(Connection connection, AsyncHttpContext context) : base(connection) { this.fContext = context; }
private void ResponseBodyCallback(IAsyncResult ar) { try { DataConnection.EndWrite(ar); if (ar.AsyncState is Stream) { Stream lData = (Stream)ar.AsyncState; Int32 lLen = lData.Read(fBodyBuffer, 0, fBodyBuffer.Length); if (lLen != 0) { DataConnection.BeginWrite(fBodyBuffer, 0, lLen, new AsyncCallback(ResponseBodyCallback), lData); return; } } else if (ar.AsyncState is Byte[]) { Byte[] lData = (Byte[])ar.AsyncState; Int32 lLen = fBodyBuffer.Length; if (fBodyOffset + lLen > lData.Length) lLen = lData.Length - fBodyOffset; if (lLen != 0) { Array.Copy(lData, fBodyOffset, fBodyBuffer, 0, lLen); fBodyOffset += lLen; DataConnection.BeginWrite(fBodyBuffer, 0, lLen, new AsyncCallback(ResponseBodyCallback), lData); return; } } } catch (ConnectionClosedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (SocketException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (ObjectDisposedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } AsyncHttpContext lOldContext = fContext; fContext = ((AsyncHttpServer)Owner).NewContext(this); try { DataConnection.BeginReadLine(new AsyncCallback(HeaderFirstLineCallback), null); } catch (SocketException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (ObjectDisposedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } ((AsyncHttpServer)Owner).TriggerOnHttpResponseSent(DataConnection, lOldContext); return; }
internal protected virtual void TriggerOnHttpResponseFailed(Connection connection, AsyncHttpContext context) { if (this.OnHttpResponseFailed != null) { OnAsyncHttpRequestArgs lEventArgs = new OnAsyncHttpRequestArgs(connection, context); this.OnHttpResponseFailed(this, lEventArgs); } }
internal protected virtual void TriggerOnBeforeHaveData(Connection connection, AsyncHttpContext context) { if (this.OnBeforeHaveData != null) { OnAsyncHttpRequestArgs lEventArgs = new OnAsyncHttpRequestArgs(connection, context); this.OnBeforeHaveData(this, lEventArgs); } }
private void ResponseBodyCallback(IAsyncResult ar) { try { DataConnection.EndWrite(ar); if (ar.AsyncState is Stream) { Stream lData = (Stream)ar.AsyncState; Int32 lLen = lData.Read(fBodyBuffer, 0, fBodyBuffer.Length); if (lLen != 0) { DataConnection.BeginWrite(fBodyBuffer, 0, lLen, ResponseBodyCallback, lData); return; } } else if (ar.AsyncState is Byte[]) { Byte[] lData = (Byte[])ar.AsyncState; Int32 lLen = fBodyBuffer.Length; if (fBodyOffset + lLen > lData.Length) lLen = lData.Length - fBodyOffset; if (lLen != 0) { Array.Copy(lData, fBodyOffset, fBodyBuffer, 0, lLen); fBodyOffset += lLen; DataConnection.BeginWrite(fBodyBuffer, 0, lLen, ResponseBodyCallback, lData); return; } } } catch (ConnectionClosedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (SocketException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (ObjectDisposedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } //AsyncHttpContext lOldContext = fContext; fContext = this.fOwner.NewContext(this); try { DataConnection.BeginReadLine(HeaderFirstLineCallback, null); } catch (SocketException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } catch (ObjectDisposedException) { this.fOwner.TriggerHttpResponseFailed(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); Done(); return; } this.fOwner.TriggerHttpResponseSent(new AsyncHttpRequestEventArgs(this.DataConnection, this.fContext)); }
private void ResponseBodyCallback(IAsyncResult ar) { try { DataConnection.EndWrite(ar); if (ar.AsyncState is Stream) { Stream lData = (Stream)ar.AsyncState; Int32 lLen = lData.Read(fBodyBuffer, 0, fBodyBuffer.Length); if (lLen != 0) { DataConnection.BeginWrite(fBodyBuffer, 0, lLen, new AsyncCallback(ResponseBodyCallback), lData); return; } } else if (ar.AsyncState is Byte[]) { Byte[] lData = (Byte[])ar.AsyncState; Int32 lLen = fBodyBuffer.Length; if (fBodyOffset + lLen > lData.Length) { lLen = lData.Length - fBodyOffset; } if (lLen != 0) { Array.Copy(lData, fBodyOffset, fBodyBuffer, 0, lLen); fBodyOffset += lLen; DataConnection.BeginWrite(fBodyBuffer, 0, lLen, new AsyncCallback(ResponseBodyCallback), lData); return; } } } catch (ConnectionClosedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (SocketException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (ObjectDisposedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } AsyncHttpContext lOldContext = fContext; fContext = ((AsyncHttpServer)Owner).NewContext(this); try { DataConnection.BeginReadLine(new AsyncCallback(HeaderFirstLineCallback), null); } catch (SocketException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } catch (ObjectDisposedException) { ((AsyncHttpServer)Owner).TriggerOnHttpResponseFailed(DataConnection, fContext); return; } ((AsyncHttpServer)Owner).TriggerOnHttpResponseSent(DataConnection, lOldContext); return; }