System.Net.Sockets.Socket.DoBeginDisconnect C# (CSharp) Method

DoBeginDisconnect() private method

private DoBeginDisconnect ( bool reuseSocket, DisconnectOverlappedAsyncResult asyncResult ) : void
reuseSocket bool
asyncResult DisconnectOverlappedAsyncResult
return void
        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);
        }