Ejemplo n.º 1
0
        public async ReusableTask <int> SendAsync(ByteBuffer buffer, int offset, int count)
        {
            if (SlowConnection)
            {
                count = Math.Min(88, count);
            }

            await WriteStream.WriteAsync(buffer.Data, offset, count, CancellationToken.None);

            Sends.Add(count);
            return(ManualBytesSent ?? count);
        }
Ejemplo n.º 2
0
        public async ReusableTask <int> SendAsync(SocketMemory buffer)
        {
            if (SlowConnection)
            {
                buffer = buffer.Slice(0, Math.Min(88, buffer.Length));
            }

            var data = buffer.Memory.ToArray();
            await WriteStream.WriteAsync(data, 0, data.Length, CancellationToken.None);

            Sends.Add(buffer.Length);
            return(ManualBytesSent ?? buffer.Length);
        }
Ejemplo n.º 3
0
        public override async Task WriteAsync(byte[] buf, int offset, int length, CancellationToken cancel_token)
        {
            if (closedCancelSource.IsCancellationRequested)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            await WaitOrCancelTask(ct => WriteStream.WriteAsync(buf, offset, length, ct), WriteTimeout, cancel_token).ConfigureAwait(false);

            if (!closedCancelSource.IsCancellationRequested && !cancel_token.IsCancellationRequested)
            {
                writeBytesCounter.Add(length);
            }
        }
Ejemplo n.º 4
0
 public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 {
     return(WriteStream.WriteAsync(buffer, offset, count, cancellationToken));
 }
Ejemplo n.º 5
0
        public async ValueTask Write(string value, CancellationToken cancellationToken)
        {
            int length = encoding.GetByteCount(value);

            await Write(length, cancellationToken);

            if (buffer.Length < length)
            {
                // TODO: Implement max string length.
                buffer = new byte[length];
            }

            encoding.GetBytes(value, buffer.Span);
            await writeStream.WriteAsync(buffer.Slice(0, length), cancellationToken);
        }
Ejemplo n.º 6
0
 public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken)
 {
     return(WriteStream.WriteAsync(buffer, offset, count, cancellationToken));
 }