private static void DoSend(Socket socket, SocketAwaitableEventArgs args, ReadOnlyMemory <byte> memory, string name) { // The BufferList getter is much less expensive then the setter. if (args.BufferList != null) { args.BufferList = null; } #if SOCKET_STREAM_BUFFERS args.SetBuffer(MemoryMarshal.AsMemory(memory)); #else var segment = memory.GetArray(); args.SetBuffer(segment.Array, segment.Offset, segment.Count); #endif Helpers.DebugLog(name, $"## {nameof(socket.SendAsync)} {memory.Length}"); if (socket.SendAsync(args)) { Helpers.Incr(Counter.SocketSendAsyncSingleAsync); } else { Helpers.Incr(Counter.SocketSendAsyncSingleSync); args.Complete(); } }
private static void DoSend(Socket socket, SocketAwaitableEventArgs args, ReadOnlySequence <byte> buffer, string name) { if (buffer.IsSingleSegment) { DoSend(socket, args, buffer.First, name); return; } #if SOCKET_STREAM_BUFFERS if (!args.MemoryBuffer.IsEmpty) #else if (args.Buffer != null) #endif { args.SetBuffer(null, 0, 0); } args.BufferList = GetBufferList(args, buffer); Helpers.DebugLog(name, $"## {nameof(socket.SendAsync)} {buffer.Length}"); if (socket.SendAsync(args)) { Helpers.Incr(Counter.SocketSendAsyncMultiAsync); } else { Helpers.Incr(Counter.SocketSendAsyncMultiSync); args.Complete(); } }