public ReusableTask <int> SendAsync(ByteBuffer buffer, int offset, int count) { SocketAsyncEventArgs args = GetSocketAsyncEventArgs(buffer); args.SetBuffer(offset, count); args.UserToken = SendTcs; #if ALLOW_EXECUTION_CONTEXT_SUPPRESSION AsyncFlowControl?control = null; if (!ExecutionContext.IsFlowSuppressed()) { control = ExecutionContext.SuppressFlow(); } #endif try { if (!Socket.SendAsync(args)) { SendTcs.SetResult(count); } } catch (ObjectDisposedException) { SendTcs.SetResult(0); } finally { #if ALLOW_EXECUTION_CONTEXT_SUPPRESSION control?.Undo(); #endif } return(SendTcs.Task); }
public ReusableTask <int> SendAsync(byte[] buffer, int offset, int count) { // If this has been disposed, then bail out if (Socket == null) { SendTcs.SetResult(0); return(SendTcs.Task); } var args = GetSocketAsyncEventArgs(buffer); args.SetBuffer(offset, count); args.UserToken = SendTcs; AsyncFlowControl?control = null; if (!ExecutionContext.IsFlowSuppressed()) { control = ExecutionContext.SuppressFlow(); } try { if (!Socket.SendAsync(args)) { SendTcs.SetResult(count); } } finally { if (control.HasValue) { control.Value.Undo(); } } return(SendTcs.Task); }
public ReusableTask <int> SendAsync(byte[] buffer, int offset, int count) { // If this has been disposed, then bail out if (Socket == null) { SendTcs.SetResult(0); return(SendTcs.Task); } SocketAsyncEventArgs args = GetSocketAsyncEventArgs(buffer); args.SetBuffer(offset, count); args.UserToken = SendTcs; #if ALLOW_EXECUTION_CONTEXT_SUPPRESSION AsyncFlowControl?control = null; if (!ExecutionContext.IsFlowSuppressed()) { control = ExecutionContext.SuppressFlow(); } #endif try { if (!Socket.SendAsync(args)) { SendTcs.SetResult(count); } } finally { #if ALLOW_EXECUTION_CONTEXT_SUPPRESSION control?.Undo(); #endif } return(SendTcs.Task); }
public ReusableTask <int> SendAsync(SocketMemory buffer) { SocketAsyncEventArgs args = GetSocketAsyncEventArgs(buffer); args.UserToken = SendTcs; AsyncFlowControl?control = null; if (!ExecutionContext.IsFlowSuppressed()) { control = ExecutionContext.SuppressFlow(); } try { if (!Socket.SendAsync(args)) { SendTcs.SetResult(buffer.Length); } } catch (ObjectDisposedException) { SendTcs.SetResult(0); } finally { control?.Undo(); } return(SendTcs.Task); }
public ReusableTask <int> SendAsync(Memory <byte> buffer) { if (Socket is null) { throw new InvalidOperationException("The underlying socket is not connected"); } if (SendArgs == null) { SendArgs = new SocketAsyncEventArgs(); SendArgs.Completed += Handler; SendArgs.UserToken = SendTcs; } SetBuffer(SendArgs, buffer); SocketAsyncEventArgs args = SendArgs; AsyncFlowControl?control = null; if (!ExecutionContext.IsFlowSuppressed()) { control = ExecutionContext.SuppressFlow(); } try { if (!Socket.SendAsync(args)) { SendTcs.SetResult(buffer.Length); } } catch (ObjectDisposedException) { SendTcs.SetResult(0); } finally { control?.Undo(); } return(SendTcs.Task); }