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); }
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); }
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); } }
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { return(WriteStream.WriteAsync(buffer, offset, count, cancellationToken)); }
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); }
public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { return(WriteStream.WriteAsync(buffer, offset, count, cancellationToken)); }