Esempio n. 1
0
        internal static void CompleteInitialization(SafeCloseSocketAndEvent socketAndEventHandle)
        {
            SafeWaitHandle safeWaitHandle = socketAndEventHandle.waitHandle.SafeWaitHandle;
            bool           success        = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                safeWaitHandle.DangerousAddRef(ref success);
            }
            catch
            {
                if (success)
                {
                    safeWaitHandle.DangerousRelease();
                    socketAndEventHandle.waitHandle = null;
                    success = false;
                }
            }
            finally
            {
                if (success)
                {
                    safeWaitHandle.Dispose();
                }
            }
        }
Esempio n. 2
0
        internal static SafeCloseSocketAndEvent CreateWSASocketWithEvent(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, bool autoReset, bool signaled)
        {
            SafeCloseSocketAndEvent target = new SafeCloseSocketAndEvent();

            SafeCloseSocket.CreateSocket(SafeCloseSocket.InnerSafeCloseSocket.CreateWSASocket(addressFamily, socketType, protocolType), target);
            if (target.IsInvalid)
            {
                throw new SocketException();
            }
            target.waitHandle = new AutoResetEvent(false);
            CompleteInitialization(target);
            return(target);
        }
        internal NetworkAddressChangePolled()
        {
            int num;

            Socket.InitializeSockets();
            if (Socket.OSSupportsIPv4)
            {
                num             = -1;
                this.ipv4Socket = SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.IP, true, false);
                UnsafeNclNativeMethods.OSSOCK.ioctlsocket(this.ipv4Socket, -2147195266, ref num);
            }
            if (Socket.OSSupportsIPv6)
            {
                num             = -1;
                this.ipv6Socket = SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.IP, true, false);
                UnsafeNclNativeMethods.OSSOCK.ioctlsocket(this.ipv6Socket, -2147195266, ref num);
            }
            this.Setup(StartIPOptions.Both);
        }
 public void Dispose()
 {
     if (!this.disposed)
     {
         lock (this)
         {
             if (!this.disposed)
             {
                 if (this.ipv6Socket != null)
                 {
                     this.ipv6Socket.Close();
                     this.ipv6Socket = null;
                 }
                 if (this.ipv4Socket != null)
                 {
                     this.ipv4Socket.Close();
                     this.ipv6Socket = null;
                 }
                 this.disposed = true;
             }
         }
     }
 }