public void BeginRead(ConnectionContextTPL connectionContext) { InputStreamContext ctx = new InputStreamContext(connectionContext, bufferSize); Task<int>.Factory.FromAsync<byte[], int, int>(ctx.ConnectionContext.ClientStream.BeginRead, ctx.ConnectionContext.ClientStream.EndRead, ctx.Header, 0, sizeof(long), ctx).ContinueWith(BeginReadCallback); }
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; Task<int>.Factory.FromAsync<byte[], int, int>(ctx.ConnectionContext.ClientStream.BeginRead, ctx.ConnectionContext.ClientStream.EndRead, ctx.Buffer, 0, bytesToRead, ctx).ContinueWith(BeginReadCallback); }
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); }