Exemplo n.º 1
0
		// don't change for default, otherwise breaking change

		// this version does not throw.
		internal void InternalShutdown (SocketShutdown how)
		{
			if (!is_connected || is_disposed)
				return;
			int error;
			Shutdown_internal (safe_handle, how, out error);
		}
Exemplo n.º 2
0
		// don't change for default, otherwise breaking change

		// this version does not throw.
		internal void InternalShutdown (SocketShutdown how)
		{
			if (!is_connected || CleanedUp)
				return;
			int error;
			Shutdown_internal (m_Handle, how, out error);
		}
Exemplo n.º 3
0
		// don't change for default, otherwise breaking change

		// this version does not throw.
		internal void InternalShutdown (SocketShutdown how)
		{
			if (!connected || disposed)
				return;
			int error;
			Shutdown_internal (socket, how, out error);
		}
Exemplo n.º 4
0
 public static void ShutdownSilently(this Socket socket, SocketShutdown how)
 {
     try
     {
         socket.Shutdown(how);
     }
     catch (SocketException)
     {
         // ignore
     }
     catch (ObjectDisposedException)
     {
         // ignore
     }
 }
Exemplo n.º 5
0
 internal static Error Shutdown(SafeHandle socket, SocketShutdown how)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousShutdown((int)socket.DangerousGetHandle(), how);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
Exemplo n.º 6
0
 private void CloseConnection(SocketShutdown soShutdown)
 {
     if (soShutdown == SocketShutdown.Receive)
     {
         myLogger.Log("Remember that you're in a Client, you can't only close Both connections or only your connection.");
         return;
     }
     if (ClientSocket.Connected)
     {
         ClientSocket.Disconnect(false);
         if (ClientSocket.Connected)
         {
             ClientSocket.Shutdown(soShutdown);
         }
     }
 }
Exemplo n.º 7
0
 public static bool Shutdown([In] Socket socket, [In] SocketShutdown how)
 {
     if (Platform.IsWindows())
     {
         return(shutdown(socket.Handle, how) == SocketError.Success);
     }
     try
     {
         socket.Shutdown(how);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Shuts down the socket.
        /// </summary>
        /// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
        private void ShutdownSocket(SocketShutdown how)
        {
            if (_socket == null || !_socket.Connected)
            {
                return;
            }

            lock (_socketShutdownAndCloseLock)
            {
                if (_socket == null || !_socket.Connected)
                {
                    return;
                }

                _socket.Shutdown(how);
            }
        }
Exemplo n.º 9
0
        internal static Error Shutdown(SafeHandle socket, SocketShutdown how)
        {
            bool release = false;

            try
            {
                socket.DangerousAddRef(ref release);
                return(DangerousShutdown((int)socket.DangerousGetHandle(), how));
            }
            finally
            {
                if (release)
                {
                    socket.DangerousRelease();
                }
            }
        }
Exemplo n.º 10
0
        public void Shutdown(SocketShutdown how)
        {
            switch (how)
            {
            case SocketShutdown.Receive:
                this.CloseState |= CloseState.ReceiveClosed;
                break;

            case SocketShutdown.Send:
                this.CloseState |= CloseState.SendClosed;
                break;

            case SocketShutdown.Both:
                this.CloseState |= CloseState.Both;
                break;
            }
        }
Exemplo n.º 11
0
        public static bool TryShutdown(this Socket socket, SocketShutdown shutdown)
        {
            if (socket == null)
            {
                return(true);
            }

            try
            {
                socket.Shutdown(shutdown);
                return(true);
            }
            catch (Exception ex)
            {
                ex.WriteToExcpetionBuffer();
                return(false);
            }
        }
Exemplo n.º 12
0
        public void Shutdown(SocketShutdown how)
        {
            switch (how)
            {
            case SocketShutdown.Send:
                ShutdownSendCalled = true;
                break;

            case SocketShutdown.Receive:
                ShutdownReceiveCalled = true;
                break;

            case SocketShutdown.Both:
                ShutdownSendCalled    = true;
                ShutdownReceiveCalled = true;
                break;
            }
        }
Exemplo n.º 13
0
        public async Task ShutdownReceiveBeforeOperation_ThrowsSocketException(SocketShutdown shutdown)
        {
            using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.BindToAnonymousPort(IPAddress.Any);
            socket.Shutdown(shutdown);

            // [ActiveIssue("https://github.com/dotnet/runtime/issues/47469")]
            // Shutdown(Both) does not seem to take immediate effect for Receive(Message)From in a consistent manner, trying to workaround with a delay:
            if (shutdown == SocketShutdown.Both)
            {
                await Task.Delay(50);
            }

            SocketException exception = await Assert.ThrowsAnyAsync <SocketException>(() => ReceiveMessageFromAsync(socket, new byte[1], GetGetDummyTestEndpoint()))
                                        .TimeoutAfter(CancellationTestTimeout);

            Assert.Equal(SocketError.Shutdown, exception.SocketErrorCode);
        }
Exemplo n.º 14
0
 public void Shutdown(SocketShutdown how)
 {
                 #if cooper
     if (fIsServer)
     {
         fServerHandle.close();
     }
     else
     {
         fHandle.close();
     }
                 #else
     if (rtl.shutdown(fHandle, (int)how) != 0)
     {
         throw new Exception("Error closing socket");
     }
                 #endif
 }
Exemplo n.º 15
0
        public void Shutdown(SocketShutdown how)
        {
            if (disposed && closed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            if (!connected)
            {
                throw new SocketException(10057);                  // Not connected
            }
            int error;

            Shutdown_internal(socket, how, out error);
            if (error != 0)
            {
                throw new SocketException(error);
            }
        }
Exemplo n.º 16
0
		public void Shutdown(SocketShutdown how)
		{
			if (_isClosed) {
				throw new ObjectDisposedException("Socket has been closed");
			}
			int ztHow = 0;
			switch (how)
			{
				case SocketShutdown.Receive:
					ztHow = Constants.O_RDONLY;
					break;
				case SocketShutdown.Send:
					ztHow = Constants.O_WRONLY;
					break;
				case SocketShutdown.Both:
					ztHow = Constants.O_RDWR;
					break;
			}
			zts_shutdown(_fd, ztHow);
		}
Exemplo n.º 17
0
 internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout, bool silent)
 {
     if (timeout < 0)
     {
         timeout = 0;
     }
     System.Net.Sockets.Socket streamSocket = this.m_StreamSocket;
     if (streamSocket != null)
     {
         if (((mode == SocketShutdown.Send) || (mode == SocketShutdown.Both)) && (timeout != this.m_CurrentWriteTimeout))
         {
             streamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout, silent);
             this.m_CurrentWriteTimeout = timeout;
         }
         if (((mode == SocketShutdown.Receive) || (mode == SocketShutdown.Both)) && (timeout != this.m_CurrentReadTimeout))
         {
             streamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout, silent);
             this.m_CurrentReadTimeout = timeout;
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Shuts down the socket.
        /// </summary>
        /// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
        private void ShutdownSocket(SocketShutdown how)
        {
            if (_socket == null)
            {
                return;
            }

            lock (_socketLock)
            {
#if DEBUG_GERT
                Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.ShutdownSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff"));
#endif // DEBUG_GERT

                if (_socket == null || !_socket.Connected)
                {
                    return;
                }

                _socket.Shutdown(how);
            }
        }
Exemplo n.º 19
0
        public const int STREAM_SHUT_RDWR = (int)SocketShutdown.Both;    // 2;

        /// <summary>
        /// Shutdown a full-duplex connection.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="how">One of the following constants:
        /// - STREAM_SHUT_RD (disable further receptions)<br />
        /// - STREAM_SHUT_WR (disable further transmissions)<br />
        /// - STREAM_SHUT_RDWR (disable further receptions and transmissions).<br/>
        /// </param>
        /// <returns></returns>
        public static bool stream_socket_shutdown(PhpResource stream, SocketShutdown how)
        {
            var s = SocketStream.GetValid(stream);

            if (s != null)
            {
                try
                {
                    s.Socket.Shutdown(how);
                }
                catch (SocketException ex)
                {
                    PhpException.Throw(PhpError.Warning, ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 20
0
 public void Shutdown(SocketShutdown How)
 {
     lock (Lockee)
     {
         if (IsDisposed)
         {
             return;
         }
         //Mono(3.0.4)上在对方先Shutdown的时候后,某个时候Connected会变为False,但时机不确定,所以需要判断和捕捉异常。
         try
         {
             if (InnerSocket.Connected)
             {
                 InnerSocket.Shutdown(How);
             }
         }
         catch (SocketException)
         {
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Shuts down the socket.
        /// </summary>
        /// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
        private void ShutdownSocket(SocketShutdown how)
        {
#if DEBUG_GERT
            Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket");
#endif // DEBUG_GERT

            if (_socket == null || !_socket.Connected)
            {
                return;
            }

            lock (_socketShutdownAndCloseLock)
            {
                var socket = _socket;
                if (socket == null || !socket.Connected)
                {
                    return;
                }

                socket.Shutdown(how);
            }
        }
Exemplo n.º 22
0
        internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout)
        {
            if (timeout < 0)
            {
                timeout = 0;
            }
            Socket streamSocket = this.m_StreamSocket;

            if (streamSocket == null)
            {
                return;
            }
            if ((mode == SocketShutdown.Send || mode == SocketShutdown.Both) && timeout != this.m_CurrentWriteTimeout)
            {
                streamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);
                this.m_CurrentWriteTimeout = timeout;
            }
            if ((mode == SocketShutdown.Receive || mode == SocketShutdown.Both) && timeout != this.m_CurrentReadTimeout)
            {
                streamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout);
                this.m_CurrentReadTimeout = timeout;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// ソケットの終了処理を行います。
        /// </summary>
        public void Shutdown(SocketShutdown shutdown = SocketShutdown.Send)
        {
            try
            {
                lock (this.socketLock)
                {
                    if (Socket == null)
                    {
                        return;
                    }

                    // すでに読み取り不可なら、その状態は変わりません。
                    //
                    // また、SocketShutdownにFlags属性はありません。
                    //  SocketShutdown.Receive || SocketShutdown.Both
                    // が指定されたときは、読み取り不可で
                    //  !(SocketShutdown.Receive || SocketShutdown.Both)
                    //    => SocketShutdown.Send
                    // の場合のみ、読み取り可能となります。
                    CanRead = (CanRead &&
                               shutdown == SocketShutdown.Send);
                    CanWrite = (CanWrite &&
                                shutdown == SocketShutdown.Receive);

                    // ソケットの切断処理を開始します。
                    Socket.Shutdown(shutdown);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException(this, ex,
                                   "ソケットのShutdownに失敗しました。");

                Util.ThrowIfFatal(ex);
                NotifyDisconnected(DisconnectReason.Error);
            }
        }
Exemplo n.º 24
0
        public void Shutdown_internal(SocketShutdown how, out int error)
        {
            error = 0;

            if (jSocket == null || !jSocket.isConnected())
            {
                error = 10057;                 //WSAENOTCONN (Socket is not connected)
                return;
            }

            try
            {
                switch (how)
                {
                case SocketShutdown.Receive:
                    jSocket.shutdownInput();
                    break;

                case SocketShutdown.Send:
                    jSocket.shutdownOutput();
                    break;

                case SocketShutdown.Both:
                    jSocket.shutdownInput();
                    jSocket.shutdownOutput();
                    break;
                }
            }
            catch (Exception e)
            {
                error = 10022;                 //WSAEINVAL (Invalid argument)
#if DEBUG
                Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }
        }
Exemplo n.º 25
0
        internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout, bool silent)
        {
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("NetworkStream#" + LoggingHash.HashString(this) + "::SetSocketTimeoutOption() mode:" + mode + " silent:" + silent + " timeout:" + timeout + " m_CurrentReadTimeout:" + _currentReadTimeout + " m_CurrentWriteTimeout:" + _currentWriteTimeout);
            }
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "NetworkStream#" + LoggingHash.HashString(this) + "::SetSocketTimeoutOption");

            if (timeout < 0)
            {
                timeout = 0; // -1 becomes 0 for the winsock stack
            }

            Socket chkStreamSocket = _streamSocket;

            if (chkStreamSocket == null)
            {
                return;
            }
            if (mode == SocketShutdown.Send || mode == SocketShutdown.Both)
            {
                if (timeout != _currentWriteTimeout)
                {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout, silent);
                    _currentWriteTimeout = timeout;
                }
            }
            if (mode == SocketShutdown.Receive || mode == SocketShutdown.Both)
            {
                if (timeout != _currentReadTimeout)
                {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout, silent);
                    _currentReadTimeout = timeout;
                }
            }
        }
Exemplo n.º 26
0
        internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout, bool silent)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this, mode, timeout, silent);
            }
            DebugThreadTracking.ThreadContract(ThreadKinds.Unknown, $"NetworkStream#{NetEventSource.IdOf(this)}");

            if (timeout < 0)
            {
                timeout = 0; // -1 becomes 0 for the winsock stack
            }

            Socket chkStreamSocket = _streamSocket;

            if (chkStreamSocket == null)
            {
                return;
            }
            if (mode == SocketShutdown.Send || mode == SocketShutdown.Both)
            {
                if (timeout != _currentWriteTimeout)
                {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout, silent);
                    _currentWriteTimeout = timeout;
                }
            }
            if (mode == SocketShutdown.Receive || mode == SocketShutdown.Both)
            {
                if (timeout != _currentReadTimeout)
                {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout, silent);
                    _currentReadTimeout = timeout;
                }
            }
        }
Exemplo n.º 27
0
		static void Shutdown_internal (SafeSocketHandle safeHandle, SocketShutdown how, out int error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				Shutdown_internal (safeHandle.DangerousGetHandle (), how, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Exemplo n.º 28
0
 public void Shutdown(SocketShutdown how)
 {
     _remote.Shutdown(how);
 }
Exemplo n.º 29
0
        // This version does not throw.
        internal void InternalShutdown(SocketShutdown how)
        {
            GlobalLog.Print("Socket#" + Logging.HashString(this) + "::InternalShutdown() how:" + how.ToString());

            if (CleanedUp || _handle.IsInvalid)
            {
                return;
            }

            try
            {
                SocketPal.Shutdown(_handle, _isConnected, _isDisconnected, how);
            }
            catch (ObjectDisposedException) { }
        }
Exemplo n.º 30
0
 void Utils.Wrappers.Interfaces.ISocket.Shutdown(SocketShutdown how)
 {
     InternalSocket.Shutdown(how);
 }
Exemplo n.º 31
0
		public void Shutdown (SocketShutdown how)
		{
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			if (!connected)
				throw new SocketException (10057); // Not connected

			int error;
			
			Shutdown_internal (socket, how, out error);
			if (error != 0)
				throw new SocketException (error);
		}
Exemplo n.º 32
0
        //
        //public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
        //{
        //  // TODO
        //  throw new NotSupportedException();
        //}
//
        //public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)
        //{
        //  // TODO
        //  throw new NotSupportedException();
        //}
//
        //public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue)
        //{
        //  SetSocketOption(optionLevel, optionName, (optionValue?1:0));
        //}
        //

        public void Shutdown(SocketShutdown how)
        {
            internalSocket.Shutdown(how);
        }
Exemplo n.º 33
0
 virtual internal void Shutdown(SocketShutdown how)
 {
     CheckDisposed();
     _socket.Shutdown(how);
 }
Exemplo n.º 34
0
 public abstract void Shutdown(SocketShutdown how);
Exemplo n.º 35
0
 public void Shutdown(SocketShutdown how)
 {
     _remote.Shutdown(how);
 }
Exemplo n.º 36
0
        /// <summary>
        /// Shuts down the socket.
        /// </summary>
        /// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
        private void ShutdownSocket(SocketShutdown how)
        {
#if DEBUG_GERT
            Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket");
#endif // DEBUG_GERT

            if (_socket == null || !_socket.Connected)
                return;

            lock (_socketShutdownAndCloseLock)
            {
                var socket = _socket;
                if (socket == null || !socket.Connected)
                    return;

                socket.Shutdown(how);
            }
        }
 internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout, bool silent)
 {
     m_NetworkStream.SetSocketTimeoutOption(mode, timeout, silent);
 }
Exemplo n.º 38
0
        /// <summary>
        /// Shuts down the socket.
        /// </summary>
        /// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
        private void ShutdownSocket(SocketShutdown how)
        {
            if (_socket == null)
                return;

            lock (_socketLock)
            {
                if (_socket == null || !_socket.Connected)
                    return;

                _socket.Shutdown(how);
            }
        }
Exemplo n.º 39
0
 public void Shutdown(SocketShutdown type)
 {
     Connection.Shutdown(type);
 }
Exemplo n.º 40
0
 internal void Shutdown(SocketShutdown how) { internalSocket.Shutdown(how); }
Exemplo n.º 41
0
 public override void Shutdown(SocketShutdown how)
 {
     socket.Shutdown(how);
 }
Exemplo n.º 42
0
 /// <summary>
 /// Shutdowns socket.
 /// </summary>
 /// <param name="how"></param>
 public void Shutdown(SocketShutdown how)
 {
     m_pSocket.Shutdown(how);
 }
Exemplo n.º 43
0
        public static SocketError Shutdown(SafeCloseSocket handle, bool isConnected, bool isDisconnected, SocketShutdown how)
        {
            Interop.Error err = Interop.Sys.Shutdown(handle.FileDescriptor, how);
            if (err == Interop.Error.SUCCESS)
            {
                return SocketError.Success;
            }

            // If shutdown returns ENOTCONN and we think that this socket has ever been connected,
            // ignore the error. This can happen for TCP connections if the underlying connection
            // has reached the CLOSE state. Ignoring the error matches Winsock behavior.
            if (err == Interop.Error.ENOTCONN && (isConnected || isDisconnected))
            {
                return SocketError.Success;
            }

            return GetSocketErrorForErrorCode(err);
        }
Exemplo n.º 44
0
        public static SocketError Shutdown(SafeCloseSocket handle, bool isConnected, bool isDisconnected, SocketShutdown how)
        {
            SocketError err = Interop.Winsock.shutdown(handle, (int)how);
            if (err != SocketError.SocketError)
            {
                return SocketError.Success;
            }

            err = GetLastSocketError();
            Debug.Assert(err != SocketError.NotConnected || (!isConnected && !isDisconnected));
            return err;
        }
Exemplo n.º 45
0
        public static SocketError Shutdown(SafeCloseSocket handle, bool isConnected, bool isDisconnected, SocketShutdown how)
        {
            SocketError err = Interop.Winsock.shutdown(handle, (int)how);

            if (err != SocketError.SocketError)
            {
                return(SocketError.Success);
            }

            err = GetLastSocketError();
            Debug.Assert(err != SocketError.NotConnected || (!isConnected && !isDisconnected));
            return(err);
        }
Exemplo n.º 46
0
        /// <devdoc>
        ///    <para>
        ///       Disables sends and receives on a socket.
        ///    </para>
        /// </devdoc>
        public void Shutdown(SocketShutdown how) {
            if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Shutdown", how);
            if (CleanedUp) {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::Shutdown() how:" + how.ToString());

            // This can throw ObjectDisposedException.
            SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.shutdown(m_Handle, (int) how);

            //
            // if the native call fails we'll throw a SocketException
            //
            errorCode = errorCode!=SocketError.SocketError ? SocketError.Success : (SocketError)Marshal.GetLastWin32Error();

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::Shutdown() UnsafeNclNativeMethods.OSSOCK.shutdown returns errorCode:" + errorCode);

            //
            // skip good cases: success, socket already closed
            //
            if (errorCode!=SocketError.Success && errorCode!=SocketError.NotSocket) {
                //
                // 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, "Shutdown", socketException );
                throw socketException;
            }

            SetToDisconnected();
            InternalSetBlocking(willBlockInternal);
            if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Shutdown", "");
        }
 public void Shutdown( SocketShutdown shutDownType )
 {
     fSocket.Shutdown( shutDownType );
 }
Exemplo n.º 48
0
        // this version does not throw.
        internal void InternalShutdown(SocketShutdown how) {
            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::InternalShutdown() how:" + how.ToString());

            if (CleanedUp || m_Handle.IsInvalid) {
                return;
            }

            try
            {
                UnsafeNclNativeMethods.OSSOCK.shutdown(m_Handle, (int)how);
            }
            catch (ObjectDisposedException) { }
        }
Exemplo n.º 49
0
        // Disables sends and receives on a socket.
        public void Shutdown(SocketShutdown how)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "Shutdown", how);
            }
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            GlobalLog.Print("Socket#" + Logging.HashString(this) + "::Shutdown() how:" + how.ToString());

            // This can throw ObjectDisposedException.
            SocketError errorCode = SocketPal.Shutdown(_handle, _isConnected, _isDisconnected, how);

            GlobalLog.Print("Socket#" + Logging.HashString(this) + "::Shutdown() Interop.Winsock.shutdown returns errorCode:" + errorCode);

            // Skip good cases: success, socket already closed.
            if (errorCode != SocketError.Success && errorCode != SocketError.NotSocket)
            {
                // 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, "Shutdown", socketException);
                }
                throw socketException;
            }

            SetToDisconnected();
            InternalSetBlocking(_willBlockInternal);
            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "Shutdown", "");
            }
        }
Exemplo n.º 50
0
        public static int GetPlatformSocketShutdown(SocketShutdown how)
        {
            switch (how)
            {
                case SocketShutdown.Receive:
                    return Interop.libc.SHUT_RD;

                case SocketShutdown.Send:
                    return Interop.libc.SHUT_WR;

                case SocketShutdown.Both:
                    return Interop.libc.SHUT_RDWR;

                default:
                    // TODO: rethink this
                    return (int)how;
            }
        }
Exemplo n.º 51
0
 /// <summary>
 /// Shuts down this StringSocket.
 /// </summary>
 public void Shutdown(SocketShutdown mode)
 {
     socket.Shutdown(mode);
 }
Exemplo n.º 52
0
        internal void SetSocketTimeoutOption(SocketShutdown mode, int timeout, bool silent) {
            GlobalLog.Print("NetworkStream#" + ValidationHelper.HashString(this) + "::SetSocketTimeoutOption() mode:" + mode + " silent:" + silent + " timeout:" + timeout + " m_CurrentReadTimeout:" + m_CurrentReadTimeout + " m_CurrentWriteTimeout:" + m_CurrentWriteTimeout);
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "NetworkStream#" + ValidationHelper.HashString(this) + "::SetSocketTimeoutOption");

            if (timeout < 0) {
                timeout = 0; // -1 becomes 0 for the winsock stack
            }

            Socket chkStreamSocket = m_StreamSocket;
            if (chkStreamSocket==null) {
                return;
            }
            if (mode==SocketShutdown.Send || mode==SocketShutdown.Both) {
                if (timeout!=m_CurrentWriteTimeout) {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout, silent);
                    m_CurrentWriteTimeout = timeout;
                }
            }
            if (mode==SocketShutdown.Receive || mode==SocketShutdown.Both) {
                if (timeout!=m_CurrentReadTimeout) {
                    chkStreamSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout, silent);
                    m_CurrentReadTimeout = timeout;
                }
            }
        }
Exemplo n.º 53
0
		public void Shutdown (SocketShutdown how)
		{
			ThrowIfDisposedAndClosed ();

			if (!is_connected)
				throw new SocketException (10057); // Not connected

			int error;
			Shutdown_internal (safe_handle, how, out error);

			if (error != 0)
				throw new SocketException (error);
		}
Exemplo n.º 54
0
		/// <summary>
		/// Shuts down the secure connection.
		/// </summary>
		/// <exception cref="ObjectDisposedException">SecureSocket has been closed.</exception>
		/// <exception cref="SocketException">An operating system error occurs while accessing the SecureSocket.</exception>
		/// <exception cref="SecurityException">An error occurs while shutting the secure connection down.</exception>
		public override void Shutdown(SocketShutdown how) {
			this.EndShutdown(this.BeginShutdown(null, null));
		}
Exemplo n.º 55
0
		internal extern static void Shutdown_internal (IntPtr socket, SocketShutdown how, out int error);
Exemplo n.º 56
0
        private void SafeSetSocketTimeout(SocketShutdown mode) {

            if(Eof){
                return;
            }

            int timeout;
            if (mode == SocketShutdown.Receive) {
                timeout = ReadTimeout;
            } else /*if (mode == SocketShutdown.Send)*/ {
                timeout = WriteTimeout;
            }
            Connection connection = m_Connection;
            if (connection!=null) {
                NetworkStream networkStream = connection.NetworkStream;
                if (networkStream!=null) {
                    networkStream.SetSocketTimeoutOption(mode, timeout, false);
                }
            }
        }
Exemplo n.º 57
0
 internal static extern Error Shutdown(int socket, SocketShutdown how);
Exemplo n.º 58
0
 public static void SafeClose(this Socket socket, SocketShutdown down)
 {
     try
     {
         if (socket != null && socket.Connected)
         {
             socket.Shutdown(down);
             socket.Close();
         }
     }
     catch { }
 }
Exemplo n.º 59
0
 public void Shutdown(SocketShutdown how)
 {
     _socket.Shutdown(how);
 }
Exemplo n.º 60
0
		public void Shutdown_internal(SocketShutdown how, out int error)
		{
			error = 0;

			if (jSocket == null || !jSocket.isConnected())
			{
				error = 10057; //WSAENOTCONN (Socket is not connected)
				return;
			}

			try
			{
				switch (how)
				{
					case SocketShutdown.Receive: 
						                jSocket.shutdownInput();
						                break;
					case SocketShutdown.Send: 
										jSocket.shutdownOutput();
										break;
					case SocketShutdown.Both: 
										jSocket.shutdownInput();
										jSocket.shutdownOutput();
										break;
				}
			}
			catch (Exception e)
			{
				error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
				Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}