private static unsafe int Send(SafeCloseSocket socket, SocketFlags flags, byte[] buffer, ref int offset, ref int count, byte[] socketAddress, int socketAddressLen, out Interop.Error errno)
{
int sent;
int sockAddrLen = 0;
if (socketAddress != null)
{
sockAddrLen = socketAddressLen;
}
fixed (byte* sockAddr = socketAddress)
fixed (byte* b = buffer)
{
var iov = new Interop.Sys.IOVector {
Base = &b[offset],
Count = (UIntPtr)count
};
var messageHeader = new Interop.Sys.MessageHeader {
SocketAddress = sockAddr,
SocketAddressLen = sockAddrLen,
IOVectors = &iov,
IOVectorCount = 1
};
long bytesSent;
errno = Interop.Sys.SendMessage(socket, &messageHeader, flags, &bytesSent);
sent = checked((int)bytesSent);
}
if (errno != Interop.Error.SUCCESS)
{
return -1;
}
offset += sent;
count -= sent;
return sent;
}