public void BeginRead(ConnectionContext connectionContext)
 {
     InputStreamContext ctx = new InputStreamContext(connectionContext, bufferSize);
     ctx.ConnectionContext.ClientStream.BeginRead(ctx.Header, 0, sizeof(long) + sizeof(int), BeginReadCallback, ctx);
 }
 private void ProcessRequest(InputStreamContext ctx)
 {
     lock (ctx.ConnectionContext)
         ctx.ConnectionContext.InputQueue.Enqueue(ctx);
     BeginRead(ctx.ConnectionContext);
 }
 private void ReadChunk(InputStreamContext ctx)
 {
     int bytesToRead = ctx.RemainingBytes > ctx.Buffer.Length ? ctx.Buffer.Length : (int)ctx.RemainingBytes;
     ctx.ConnectionContext.ClientStream.BeginRead(ctx.Buffer, 0, bytesToRead, BeginReadCallback, ctx);
 }
 private void EnqueueEmptyHeader(InputStreamContext ctx)
 {
     Log.LogMessage("Writing empty header");
     InputStreamContext inputContext = new InputStreamContext(ctx.ConnectionContext, bufferSize);
     inputContext.EmptyResponse = true;
     ctx.ConnectionContext.InputQueue.Enqueue(inputContext);
 }