Esempio n. 1
0
 private void EnsureDisconnectEx(SafeCloseSocket socketHandle)
 {
     if (this.disconnectEx == null)
     {
         lock (this.lockObject)
         {
             if (this.disconnectEx == null)
             {
                 Guid   guid = new Guid("{0x7fda2e11,0x8630,0x436f,{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}");
                 IntPtr ptr  = this.LoadDynamicFunctionPointer(socketHandle, ref guid);
                 this.disconnectEx          = (DisconnectExDelegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(DisconnectExDelegate));
                 this.disconnectEx_Blocking = (DisconnectExDelegate_Blocking)Marshal.GetDelegateForFunctionPointer(ptr, typeof(DisconnectExDelegate_Blocking));
             }
         }
     }
 }
Esempio n. 2
0
        private void LoadDisconnectEx()
        {
            SocketError errorCode;
            IntPtr ptrDisconnectEx = IntPtr.Zero;

            unsafe
            {
                int length;
                Guid guid = new Guid("{0x7fda2e11,0x8630,0x436f,{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}");

                // This can throw ObjectDisposedException.
                errorCode = UnsafeNclNativeMethods.OSSOCK.WSAIoctl(
                    m_Handle,
                    IoctlSocketConstants.SIOGETEXTENSIONFUNCTIONPOINTER,
                    ref guid,
                    sizeof(Guid),
                    out ptrDisconnectEx,
                    sizeof(IntPtr),
                    out length,
                    IntPtr.Zero,
                    IntPtr.Zero);
            }

            if (errorCode != SocketError.Success)
            {
                throw new SocketException();
            }
            s_DisconnectEx = (DisconnectExDelegate) Marshal.GetDelegateForFunctionPointer(ptrDisconnectEx, typeof(DisconnectExDelegate));
            s_DisconnectEx_Blocking = (DisconnectExDelegate_Blocking)Marshal.GetDelegateForFunctionPointer(ptrDisconnectEx, typeof(DisconnectExDelegate_Blocking));
        }