// 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); }
// 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); }
// 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); }
public static void ShutdownSilently(this Socket socket, SocketShutdown how) { try { socket.Shutdown(how); } catch (SocketException) { // ignore } catch (ObjectDisposedException) { // ignore } }
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(); } } }
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); } } }
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); } }
/// <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); } }
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(); } } }
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; } }
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); } }
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; } }
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); }
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 }
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); } }
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); }
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; } } }
/// <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); } }
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); }
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) { } } }
/// <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) { 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; } }
/// <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); } }
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 } }
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; } } }
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; } } }
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 (); } }
public void Shutdown(SocketShutdown how) { _remote.Shutdown(how); }
// 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) { } }
void Utils.Wrappers.Interfaces.ISocket.Shutdown(SocketShutdown how) { InternalSocket.Shutdown(how); }
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); }
// //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); }
virtual internal void Shutdown(SocketShutdown how) { CheckDisposed(); _socket.Shutdown(how); }
public abstract void Shutdown(SocketShutdown how);
/// <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); }
/// <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); } }
public void Shutdown(SocketShutdown type) { Connection.Shutdown(type); }
internal void Shutdown(SocketShutdown how) { internalSocket.Shutdown(how); }
public override void Shutdown(SocketShutdown how) { socket.Shutdown(how); }
/// <summary> /// Shutdowns socket. /// </summary> /// <param name="how"></param> public void Shutdown(SocketShutdown how) { m_pSocket.Shutdown(how); }
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); }
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; }
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); }
/// <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 ); }
// 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) { } }
// 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", ""); } }
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; } }
/// <summary> /// Shuts down this StringSocket. /// </summary> public void Shutdown(SocketShutdown mode) { socket.Shutdown(mode); }
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; } } }
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); }
/// <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)); }
internal extern static void Shutdown_internal (IntPtr socket, SocketShutdown how, out int error);
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); } } }
internal static extern Error Shutdown(int socket, SocketShutdown how);
public static void SafeClose(this Socket socket, SocketShutdown down) { try { if (socket != null && socket.Connected) { socket.Shutdown(down); socket.Close(); } } catch { } }
public void Shutdown(SocketShutdown how) { _socket.Shutdown(how); }