本文整理汇总了C#中System.Net.SocketAddress.CopyAddressSizeIntoBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAddress.CopyAddressSizeIntoBuffer方法的具体用法?C# SocketAddress.CopyAddressSizeIntoBuffer怎么用?C# SocketAddress.CopyAddressSizeIntoBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.SocketAddress
的用法示例。
在下文中一共展示了SocketAddress.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 can be Async
//
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, SocketAddress socketAddress, bool pinSocketAddress)
{
//
// Fill in Buffer Array structure that will be used for our send/recv Buffer
//
m_SocketAddress = socketAddress;
if (pinSocketAddress && m_SocketAddress != null)
{
object[] objectsToPin = null;
objectsToPin = new object[2];
objectsToPin[0] = buffer;
m_SocketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[1] = m_SocketAddress.m_Buffer;
base.SetUnmanagedStructures(objectsToPin);
} else {
base.SetUnmanagedStructures(buffer);
}
m_SingleBuffer.Length = size;
m_SingleBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
}
示例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 can be Async
//
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, SocketAddress socketAddress, SocketFlags socketFlags)
{
m_MessageBuffer = new byte[s_WSAMsgSize];
m_WSABufferArray = new byte[s_WSABufferSize];
//ipv4 or ipv6?
IPAddress ipAddress = (socketAddress.Family == AddressFamily.InterNetworkV6
? socketAddress.GetIPAddress() : null);
bool ipv4 = (((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetwork
|| (ipAddress != null && ipAddress.IsIPv4MappedToIPv6)); // DualMode
bool ipv6 = ((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetworkV6;
//prepare control buffer
if (ipv4) {
m_ControlBuffer = new byte[s_ControlDataSize];
}
else if (ipv6) {
m_ControlBuffer = new byte[s_ControlDataIPv6Size];
}
//pin buffers
object[] objectsToPin = new object[(m_ControlBuffer != null)?5:4];
objectsToPin[0] = buffer;
objectsToPin[1] = m_MessageBuffer;
objectsToPin[2] = m_WSABufferArray;
//prepare socketaddress buffer
m_SocketAddress = socketAddress;
m_SocketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[3] = m_SocketAddress.m_Buffer;
if(m_ControlBuffer != null){
objectsToPin[4] = m_ControlBuffer;
}
base.SetUnmanagedStructures(objectsToPin);
//prepare data buffer
m_WSABuffer = (WSABuffer*) Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray, 0);
m_WSABuffer->Length = size;
m_WSABuffer->Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
//setup structure
m_Message = (UnsafeNclNativeMethods.OSSOCK.WSAMsg*) Marshal.UnsafeAddrOfPinnedArrayElement(m_MessageBuffer, 0);
m_Message->socketAddress = Marshal.UnsafeAddrOfPinnedArrayElement(m_SocketAddress.m_Buffer,0);
m_Message->addressLength = (uint)m_SocketAddress.Size;
m_Message->buffers = Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray,0);
m_Message->count = 1;
if(m_ControlBuffer != null){
m_Message->controlBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(m_ControlBuffer, 0);
m_Message->controlBuffer.Length = m_ControlBuffer.Length;
}
m_Message->flags = socketFlags;
}