Beispiel #1
0
        /// <summary>
        /// Occurs when libuv needs to allocate.
        /// </summary>
        private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize)
        {
            var result = _rawSocketInput.IncomingStart();

            return(handle.Libuv.buf_init(
                       result.DataArrayPtr + result.End,
                       result.Data.Offset + result.Data.Count - result.End));
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            var inputBuffer = _socketInput.IncomingStart(count);

            Buffer.BlockCopy(buffer, offset, inputBuffer.Data.Array, inputBuffer.Data.Offset, count);

            _socketInput.IncomingComplete(count, error: null);
        }
        public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders)
        {
            var socketInput      = new SocketInput(new MemoryPool2());
            var headerCollection = new FrameRequestHeaders();

            var headerArray = Encoding.ASCII.GetBytes(rawHeaders);
            var inputBuffer = socketInput.IncomingStart(headerArray.Length);

            Buffer.BlockCopy(headerArray, 0, inputBuffer.Data.Array, inputBuffer.Data.Offset, headerArray.Length);
            socketInput.IncomingComplete(headerArray.Length, null);

            var success = Frame.TakeMessageHeaders(socketInput, headerCollection);

            Assert.True(success);
            Assert.Equal(numHeaders, headerCollection.Count());

            // Assert TakeMessageHeaders consumed all the input
            var scan = socketInput.ConsumingStart();

            Assert.True(scan.IsEnd);
        }
        public async Task ReadInputAsync()
        {
            int bytesRead;

            do
            {
                var block = SocketInput.IncomingStart();

                try
                {
                    var count = block.Data.Offset + block.Data.Count - block.End;
                    bytesRead = await _filteredStream.ReadAsync(block.Array, block.End, count);
                }
                catch (Exception ex)
                {
                    SocketInput.IncomingComplete(0, ex);
                    throw;
                }

                SocketInput.IncomingComplete(bytesRead, error: null);
            } while (bytesRead != 0);
        }