Inheritance: BaseOverlappedAsyncResult
        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);
        }
Example #2
0
 public static SocketError DisconnectAsync(Socket socket, SafeCloseSocket handle, bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
 {
     throw new PlatformNotSupportedException();
 }
Example #3
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;
            }
        }
Example #4
0
        public IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback callback, object state)
        {
            // Start context-flowing op.  No need to lock - we don't use the context till the callback.
            DisconnectOverlappedAsyncResult asyncResult = new DisconnectOverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Post the disconnect.
            DoBeginDisconnect(reuseSocket, asyncResult);

            // Finish flowing (or call the callback), and return.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
Example #5
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);
        }
Example #6
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#" + Logging.HashString(this) + "::DoBeginDisconnect() ");

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

            SocketError errorCode = SocketPal.DisconnectAsync(this, _handle, reuseSocket, asyncResult);

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

            GlobalLog.Print("Socket#" + Logging.HashString(this) + "::DoBeginDisconnect() Interop.Winsock.DisConnectEx returns:" + errorCode.ToString());

            // Throw an appropriate SocketException if the native call fails synchronously.
            errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);

            if (errorCode != SocketError.Success)
            {
                // Update the internal state of this socket according to the error before throwing.
                SocketException socketException = new SocketException((int)errorCode);
                UpdateStatusAfterSocketError(socketException);
                if (s_loggingEnabled)
                {
                     Logging.Exception(Logging.Sockets, this, "BeginDisconnect", socketException);
                }
                throw socketException;
            }

            GlobalLog.Print("Socket#" + Logging.HashString(this) + "::DoBeginDisconnect() returning AsyncResult:" + Logging.HashString(asyncResult));
            if (s_loggingEnabled)
            {
                 Logging.Exit(Logging.Sockets, this, "BeginDisconnect", asyncResult);
            }
        }
Example #7
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;
        }
Example #8
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);
       }
 }
Example #9
0
 internal static SocketError DisconnectAsync(Socket socket, SafeCloseSocket handle, bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
 {
     throw new PlatformNotSupportedException(SR.net_sockets_disconnect_notsupported);
 }
Example #10
0
 public IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback callback, object state)
 {
     DisconnectOverlappedAsyncResult asyncResult = new DisconnectOverlappedAsyncResult(this, state, callback);
       asyncResult.StartPostingAsyncOp(false);
       this.DoBeginDisconnect(reuseSocket, asyncResult);
       asyncResult.FinishPostingAsyncOp();
       return (IAsyncResult) asyncResult;
 }
Example #11
0
        private void DoBeginDisconnect(bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
            SocketError errorCode = SocketError.Success;

            errorCode = SocketPal.DisconnectAsync(this, _handle, reuseSocket, asyncResult);

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

            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"UnsafeNclNativeMethods.OSSOCK.DisConnectEx returns:{errorCode}");

            // 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((int)errorCode);
                UpdateStatusAfterSocketError(socketException);
                if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
                throw socketException;
            }

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this, asyncResult);
        }
Example #12
0
        public IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback callback, object state)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            // Start context-flowing op.  No need to lock - we don't use the context till the callback.
            DisconnectOverlappedAsyncResult asyncResult = new DisconnectOverlappedAsyncResult(this, state, callback);
            asyncResult.StartPostingAsyncOp(false);

            // Post the disconnect.
            DoBeginDisconnect(reuseSocket, asyncResult);

            // Finish flowing (or call the callback), and return.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
Example #13
0
        private void DoBeginDisconnect(bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult)
        {
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::DoBeginDisconnect() ");
            }


            SocketError errorCode = SocketError.Success;

            errorCode = SocketPal.DisconnectAsync(this, _handle, reuseSocket, asyncResult);

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

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("Socket#" + LoggingHash.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((int)errorCode);
                UpdateStatusAfterSocketError(socketException);
                if (s_loggingEnabled)
                {
                    NetEventSource.Exception(NetEventSource.ComponentType.Socket, this, nameof(BeginDisconnect), socketException);
                }
                throw socketException;
            }

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::DoBeginDisconnect() returning AsyncResult:" + LoggingHash.HashString(asyncResult));
            }
            if (s_loggingEnabled)
            {
                NetEventSource.Exit(NetEventSource.ComponentType.Socket, this, nameof(BeginDisconnect), 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);
     }
 }