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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Resumes the paused connection (starts reading from it again).
 /// </summary>
 public void Resume()
 {
     try
     {
         _socket.ReadStart(_allocCallback, _readCallback, this);
     }
     catch (UvException)
     {
         // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected).
         // This should be treated the same as OnRead() seeing a "normalDone" condition.
         _rawSocketInput.IncomingComplete(0, null);
     }
 }
 public void IncomingCompleteCallsBufferSizeControlAdd(Mock <IBufferSizeControl> mockBufferSizeControl)
 {
     using (var memory = new MemoryPool())
         using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object))
         {
             socketInput.IncomingComplete(5, null);
             mockBufferSizeControl?.Verify(b => b.Add(5));
         }
 }
Ejemplo n.º 4
0
        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);
        }