private void NonBlockingWrite(NonBlockingReadContext context) { currentContext = context.currentContext; NonBlockingWriteContext writeContext = new NonBlockingWriteContext(); writeContext.currentContext = context.currentContext; try { MemoryStream data = Handle(context.data, context.methods, context.currentContext); writeContext.ostream = GetOutputStream(context.currentContext); writeContext.ostream.BeginWrite(data.GetBuffer(), 0, (int)data.Length, new AsyncCallback(NonBlockingWriteCallback), writeContext); } catch (Exception e) { FireErrorEvent(e, currentContext); try { if (writeContext.ostream != null) { writeContext.ostream.Close(); } context.currentContext.Response.Close(); } catch (Exception) { } return; } finally { currentContext = null; } }
protected void Handle(HttpListenerContext httpListenerContext, HproseHttpListenerMethods methods) { HproseHttpListenerContext context = new HproseHttpListenerContext(httpListenerContext); SendHeader(context); string method = context.Request.HttpMethod; if (method == "GET") { if (getEnabled) { MemoryStream data = DoFunctionList(methods, context); NonBlockingWriteContext writeContext = new NonBlockingWriteContext(); writeContext.currentContext = context; writeContext.ostream = GetOutputStream(context); writeContext.ostream.BeginWrite(data.GetBuffer(), 0, (int)data.Length, new AsyncCallback(NonBlockingWriteCallback), writeContext); } else { context.Response.StatusCode = 403; context.Response.Close(); } } else if (method == "POST") { NonBlockingHandle(context, methods); } else { context.Response.Close(); } }
private void NonBlockingWriteCallback(IAsyncResult asyncResult) { NonBlockingWriteContext context = (NonBlockingWriteContext)asyncResult.AsyncState; try { context.ostream.EndWrite(asyncResult); } catch (Exception e) { FireErrorEvent(e, context.currentContext); } finally { try { if (context.ostream.CanWrite) { context.ostream.Close(); context.currentContext.Response.Close(); } } catch (Exception) { } } }
private void NonBlockingWrite(NonBlockingReadContext context) { currentContext = context.currentContext.Context; NonBlockingWriteContext writeContext = new NonBlockingWriteContext(); writeContext.currentContext = context.currentContext; try { MemoryStream data = Handle(context.data, context.methods, context.currentContext); writeContext.ostream = GetOutputStream(context.currentContext); writeContext.ostream.BeginWrite(data.GetBuffer(), 0, (int)data.Length, new AsyncCallback(NonBlockingWriteCallback), writeContext); } catch (Exception e) { FireErrorEvent(e, context.currentContext); try { if (writeContext.ostream != null) { writeContext.ostream.Close(); } context.currentContext.Response.Close(); } catch (Exception) { } return; } finally { currentContext = null; } }