本文整理汇总了C#中Internals.CopyAddressSizeIntoBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Internals.CopyAddressSizeIntoBuffer方法的具体用法?C# Internals.CopyAddressSizeIntoBuffer怎么用?C# Internals.CopyAddressSizeIntoBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internals
的用法示例。
在下文中一共展示了Internals.CopyAddressSizeIntoBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUnmanagedStructures
// SetUnmanagedStructures
//
// Fills in overlapped Structures used in an async overlapped Winsock call.
// These calls are outside the runtime and are unmanaged code, so we need
// to prepare specific structures and ints that lie in unmanaged memory
// since the overlapped calls may complete asynchronously.
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, Internals.SocketAddress socketAddress, SocketFlags socketFlags)
{
_messageBuffer = new byte[s_wsaMsgSize];
_wsaBufferArray = new byte[s_wsaBufferSize];
bool ipv4, ipv6;
Socket.GetIPProtocolInformation(((Socket)AsyncObject).AddressFamily, socketAddress, out ipv4, out ipv6);
// Prepare control buffer.
if (ipv4)
{
_controlBuffer = new byte[s_controlDataSize];
}
else if (ipv6)
{
_controlBuffer = new byte[s_controlDataIPv6Size];
}
// Pin buffers.
object[] objectsToPin = new object[(_controlBuffer != null) ? 5 : 4];
objectsToPin[0] = buffer;
objectsToPin[1] = _messageBuffer;
objectsToPin[2] = _wsaBufferArray;
// Prepare socketaddress buffer.
_socketAddress = socketAddress;
_socketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[3] = _socketAddress.Buffer;
if (_controlBuffer != null)
{
objectsToPin[4] = _controlBuffer;
}
base.SetUnmanagedStructures(objectsToPin);
// Prepare data buffer.
_wsaBuffer = (WSABuffer*)Marshal.UnsafeAddrOfPinnedArrayElement(_wsaBufferArray, 0);
_wsaBuffer->Length = size;
_wsaBuffer->Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
// Setup structure.
_message = (Interop.Winsock.WSAMsg*)Marshal.UnsafeAddrOfPinnedArrayElement(_messageBuffer, 0);
_message->socketAddress = Marshal.UnsafeAddrOfPinnedArrayElement(_socketAddress.Buffer, 0);
_message->addressLength = (uint)_socketAddress.Size;
_message->buffers = Marshal.UnsafeAddrOfPinnedArrayElement(_wsaBufferArray, 0);
_message->count = 1;
if (_controlBuffer != null)
{
_message->controlBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(_controlBuffer, 0);
_message->controlBuffer.Length = _controlBuffer.Length;
}
_message->flags = socketFlags;
}
示例2: SetUnmanagedStructures
// SetUnmanagedStructures
//
// Fills in overlapped structures used in an async overlapped Winsock call.
// These calls are outside the runtime and are unmanaged code, so we need
// to prepare specific structures and ints that lie in unmanaged memory
// since the overlapped calls may complete asynchronously.
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, Internals.SocketAddress socketAddress, bool pinSocketAddress)
{
// Fill in Buffer Array structure that will be used for our send/recv Buffer
_socketAddress = socketAddress;
if (pinSocketAddress && _socketAddress != null)
{
object[] objectsToPin = null;
objectsToPin = new object[2];
objectsToPin[0] = buffer;
_socketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[1] = _socketAddress.Buffer;
base.SetUnmanagedStructures(objectsToPin);
}
else
{
base.SetUnmanagedStructures(buffer);
}
_singleBuffer.Length = size;
_singleBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
}