Exemplo n.º 1
0
 public Message(MessageHeader header, PooledMemoryStream payload)
 {
     Header = header.IsEmpty
         ? throw new ArgumentException("Must not be a default value", nameof(header))
         : header;
     Payload = payload ?? throw new ArgumentNullException(nameof(payload));
 }
Exemplo n.º 2
0
        internal void Receive(PooledMemoryStream readBuffer, int bytesToReceive)
        {
            var left = bytesToReceive;

            while (left != 0)
            {
                left -= readBuffer.Write(_mainStream, bytesToReceive);
            }
        }
Exemplo n.º 3
0
        public async ValueTask ReceiveAsync(PooledMemoryStream readBuffer, int bytesToReceive, CancellationToken cancellation)
        {
            var left = bytesToReceive;

            while (left != 0)
            {
                if (cancellation.IsCancellationRequested)
                {
                    throw new TaskCanceledException();
                }

                left -= await readBuffer.WriteAsync(_mainStream, bytesToReceive, cancellation).ConfigureAwait(false);
            }
        }