public void Overflow() { var bufferPool = new BufferSliceStack(1, 10); bufferPool.Pop(); bufferPool.Pop(); }
private void Init() { for (var i = 0; i < _maxAmountOfConnection; i++) { var context = CreateClientContext(_bufferSliceStack.Pop()); context.Disconnected += OnClientDisconnectedInternal; context.UnhandledExceptionCaught += OnClientException; context.SetWriteBuffer(_bufferSliceStack.Pop()); _contexts.Push(context); } }
public void Pop_Return_Pop() { var bufferPool = new BufferSliceStack(1, 100); var slice = bufferPool.Pop(); Assert.Throws <InvalidOperationException>(() => bufferPool.Pop()); ((PooledBufferSlice)slice).Dispose(); var slice2 = bufferPool.Pop(); Assert.Same(slice, slice2); }
/// <summary> /// Process message /// </summary> /// <param name="context"></param> /// <param name="message"></param> public void HandleDownstream(IPipelineHandlerContext context, IPipelineMessage message) { var msg = message as SendHttpResponse; if (msg == null) { context.SendDownstream(message); return; } var slice = _pool.Pop(); var serializer = new HttpHeaderSerializer(); var stream = new SliceStream(slice); serializer.SerializeResponse(msg.Response, stream); context.SendDownstream(new SendSlice(slice, (int)stream.Length)); if (msg.Response.Body != null) { context.SendDownstream(new SendStream(msg.Response.Body)); } if (!msg.Response.KeepAlive) { context.SendDownstream(new Close()); } }
/// <summary> /// Process message /// </summary> /// <param name="context"></param> /// <param name="message"></param> /// <remarks> /// Should always call either <see cref="IPipelineHandlerContext.SendDownstream"/> or <see cref="IPipelineHandlerContext.SendUpstream"/> /// unless the handler really wants to stop the processing. /// </remarks> public void HandleDownstream(IPipelineHandlerContext context, IPipelineMessage message) { var msg = message as SendResponse; if (msg == null) { context.SendDownstream(message); return; } var result = JsonConvert.SerializeObject(msg.Response, Formatting.None); // send header var header = new byte[5]; header[0] = 1; var lengthBuffer = BitConverter.GetBytes(result.Length); Buffer.BlockCopy(lengthBuffer, 0, header, 1, lengthBuffer.Length); context.SendDownstream(new SendBuffer(header, 0, 5)); // send JSON var slice = _bufferPool.Pop(); Encoding.UTF8.GetBytes(result, 0, result.Length, slice.Buffer, slice.Offset); context.SendDownstream(new SendSlice(slice, result.Length)); }
public void CreateBuffer() { var bufferPool = new BufferSliceStack(1, 10); var buffer = bufferPool.Pop(); Assert.NotNull(buffer); Assert.Equal(10, buffer.Count); }
/// <summary> /// Initializes a new instance of the <see cref="BodyDecoder"/> class. /// </summary> public BodyDecoder() { var slice = _bufferPool.Pop(); _stream = new SliceStream(slice); }