public static SocketError ReceiveMessageFrom(Socket socket, SafeCloseSocket handle, byte[] buffer, int offset, int size, ref SocketFlags socketFlags, Internals.SocketAddress socketAddress, out Internals.SocketAddress receiveAddress, out IPPacketInformation ipPacketInformation, out int bytesTransferred)
{
ReceiveMessageOverlappedAsyncResult asyncResult = new ReceiveMessageOverlappedAsyncResult(socket, null, null);
asyncResult.SetUnmanagedStructures(buffer, offset, size, socketAddress, socketFlags);
SocketError errorCode = SocketError.Success;
bytesTransferred = 0;
try
{
// This can throw ObjectDisposedException (retrieving the delegate AND resolving the handle).
if (socket.WSARecvMsgBlocking(
handle.DangerousGetHandle(),
Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult._messageBuffer, 0),
out bytesTransferred,
IntPtr.Zero,
IntPtr.Zero) == SocketError.SocketError)
{
errorCode = (SocketError)Marshal.GetLastWin32Error();
}
}
finally
{
asyncResult.SyncReleaseUnmanagedStructures();
}
socketFlags = asyncResult.SocketFlags;
receiveAddress = asyncResult.SocketAddress;
ipPacketInformation = asyncResult.IPPacketInformation;
return(errorCode);
}