public int Send(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// Validate input parameters.
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
if (offset < 0 || offset > buffer.Length)
{
throw new ArgumentOutOfRangeException(nameof(offset));
}
if (size < 0 || size > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException(nameof(size));
}
errorCode = SocketError.Success;
ValidateBlockingMode();
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"SRC:{LocalEndPoint} DST:{RemoteEndPoint} size:{size}");
// This can throw ObjectDisposedException.
int bytesTransferred;
errorCode = SocketPal.Send(_handle, buffer, offset, size, socketFlags, out bytesTransferred);
// Throw an appropriate SocketException if the native call fails.
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.Info(this, $"Interop.Winsock.send returns:{bytesTransferred}");
NetEventSource.DumpBuffer(this, buffer, offset, bytesTransferred);
NetEventSource.Exit(this, bytesTransferred);
}
return bytesTransferred;
}