当前位置: 首页>>代码示例>>C#>>正文


C# SocketAddress.CopyAddressSizeIntoBuffer方法代码示例

本文整理汇总了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);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:31,代码来源:_OverlappedAsyncResult.cs

示例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;
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:65,代码来源:_ReceiveMessageOverlappedAsyncResult.cs


注:本文中的System.Net.SocketAddress.CopyAddressSizeIntoBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。