internal static SocketError DisconnectAsync(Socket socket, SafeCloseSocket handle, bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            asyncResult.SetUnmanagedStructures(null);

            // This can throw ObjectDisposedException
            SocketError errorCode = SocketError.Success;

            if (!socket.DisconnectEx(handle, asyncResult.OverlappedHandle, (int)(reuseSocket ? TransmitFileOptions.ReuseSocket : 0), 0))
            {
                errorCode = GetLastSocketError();
            }

            return(errorCode);
        }
Beispiel #2
0
        internal static SocketError DisconnectAsync(Socket socket, SafeCloseSocket handle, bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            asyncResult.SetUnmanagedStructures(null);
            try
            {
                // This can throw ObjectDisposedException
                bool success = socket.DisconnectEx(
                    handle,
                    asyncResult.OverlappedHandle,
                    (int)(reuseSocket ? TransmitFileOptions.ReuseSocket : 0),
                    0);

                return(asyncResult.ProcessOverlappedResult(success, 0));
            }
            catch
            {
                asyncResult.ReleaseUnmanagedStructures();
                throw;
            }
        }
Beispiel #3
0
        private void DoBeginDisconnect(bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "BeginDisconnect",null);
            if (CleanedUp) {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginDisconnect() ");

#if FEATURE_PAL
            throw new PlatformNotSupportedException(SR.GetString(SR.WinXPRequired));
#endif


            asyncResult.SetUnmanagedStructures(null);

            SocketError errorCode=SocketError.Success;

            // This can throw ObjectDisposedException (handle, and retrieving the delegate).
            if (!DisconnectEx(m_Handle,asyncResult.OverlappedHandle, (int)(reuseSocket?TransmitFileOptions.ReuseSocket:0),0)) {
                errorCode = (SocketError)Marshal.GetLastWin32Error();
            }

            if (errorCode == SocketError.Success) {
                SetToDisconnected();
                m_RemoteEndPoint = null;
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginDisconnect() UnsafeNclNativeMethods.OSSOCK.DisConnectEx returns:" + errorCode.ToString());

            // if the asynchronous native call fails synchronously
            // we'll throw a SocketException
            //
            errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);

            if (errorCode!= SocketError.Success) {
                //
                // update our internal state after this socket error and throw
                //
                SocketException socketException = new SocketException(errorCode);
                UpdateStatusAfterSocketError(socketException);
                if(s_LoggingEnabled)Logging.Exception(Logging.Sockets,this,"BeginDisconnect", socketException);
                throw socketException;
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginDisconnect() returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
            if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "BeginDisconnect", asyncResult);
        }
Beispiel #4
0
        public static unsafe SocketError DisconnectAsync(Socket socket, SafeCloseSocket handle, bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            asyncResult.SetUnmanagedStructures(null);

            SocketError errorCode = SocketError.Success;

            // This can throw ObjectDisposedException (handle, and retrieving the delegate).
            if (!socket.DisconnectEx(handle, asyncResult.OverlappedHandle, (int)(reuseSocket ? TransmitFileOptions.ReuseSocket : 0), 0))
            {
                errorCode = GetLastSocketError();
            }

            return errorCode;
        }
Beispiel #5
0
 private void DoBeginDisconnect(bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "BeginDisconnect", (string) null);
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       asyncResult.SetUnmanagedStructures((object) null);
       SocketError errorCode = SocketError.Success;
       if (!this.DisconnectEx(this.m_Handle, asyncResult.OverlappedHandle, reuseSocket ? 2 : 0, 0))
     errorCode = (SocketError) Marshal.GetLastWin32Error();
       if (errorCode == SocketError.Success)
       {
     this.SetToDisconnected();
     this.m_RemoteEndPoint = (EndPoint) null;
       }
       SocketError socketError = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
       if (socketError != SocketError.Success)
       {
     SocketException socketException = new SocketException(socketError);
     this.UpdateStatusAfterSocketError(socketException);
     if (Socket.s_LoggingEnabled)
       Logging.Exception(Logging.Sockets, (object) this, "BeginDisconnect", (Exception) socketException);
     throw socketException;
       }
       else
       {
     if (!Socket.s_LoggingEnabled)
       return;
     Logging.Exit(Logging.Sockets, (object) this, "BeginDisconnect", (object) asyncResult);
       }
 }
 private void DoBeginDisconnect(bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
 {
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "BeginDisconnect", (string) null);
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (!ComNetOS.IsPostWin2K)
     {
         throw new PlatformNotSupportedException(SR.GetString("WinXPRequired"));
     }
     asyncResult.SetUnmanagedStructures(null);
     SocketError success = SocketError.Success;
     if (!this.DisconnectEx(this.m_Handle, asyncResult.OverlappedHandle, reuseSocket ? 2 : 0, 0))
     {
         success = (SocketError) Marshal.GetLastWin32Error();
     }
     if (success == SocketError.Success)
     {
         this.SetToDisconnected();
         this.m_RemoteEndPoint = null;
     }
     success = asyncResult.CheckAsyncCallOverlappedResult(success);
     if (success != SocketError.Success)
     {
         SocketException socketException = new SocketException(success);
         this.UpdateStatusAfterSocketError(socketException);
         if (s_LoggingEnabled)
         {
             Logging.Exception(Logging.Sockets, this, "BeginDisconnect", socketException);
         }
         throw socketException;
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "BeginDisconnect", asyncResult);
     }
 }