public int Send(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (buffers == null)
{
throw new ArgumentNullException(nameof(buffers));
}
if (buffers.Count == 0)
{
throw new ArgumentException(SR.Format(SR.net_sockets_zerolist, nameof(buffers)), nameof(buffers));
}
ValidateBlockingMode();
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"SRC:{LocalEndPoint} DST:{RemoteEndPoint}");
int bytesTransferred;
errorCode = SocketPal.Send(_handle, buffers, socketFlags, out bytesTransferred);
#if TRACE_VERBOSE
if (NetEventSource.IsEnabled)
{
try
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"SRC:{LocalEndPoint} DST:{RemoteEndPoint} Interop.Winsock.send returns errorCode:{errorCode} bytesTransferred:{bytesTransferred}");
}
catch (ObjectDisposedException) { }
}
#endif
if (errorCode != SocketError.Success)
{
// Update the internal state of this socket according to the error before throwing.
UpdateStatusAfterSocketError(errorCode);
if (NetEventSource.IsEnabled)
{
NetEventSource.Error(this, new SocketException((int)errorCode));
NetEventSource.Exit(this, 0);
}
return 0;
}
if (s_perfCountersEnabled)
{
if (bytesTransferred > 0)
{
SocketPerfCounter.Instance.Increment(SocketPerfCounterName.SocketBytesSent, bytesTransferred);
if (Transport == TransportType.Udp)
{
SocketPerfCounter.Instance.Increment(SocketPerfCounterName.SocketDatagramsSent);
}
}
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, bytesTransferred);
return bytesTransferred;
}