From ee9f0f748a6ebbc452db6e291d2c96a3899f25bf Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 18 Sep 2016 19:17:04 +0200 Subject: [PATCH] SocketExceptions that are thrown during shut down of the socket should not bubble up. Fixes PR #86. --- .../Channels/ChannelDirectTcpip.cs | 10 ++++++- .../Channels/ChannelForwardedTcpip.cs | 26 ++++++++++++++++--- src/Renci.SshNet/Session.cs | 4 +-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs index 4b0b4754..b6ba7a0b 100644 --- a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs @@ -132,7 +132,15 @@ namespace Renci.SshNet.Channels if (!_socket.IsConnected()) return; - _socket.Shutdown(how); + try + { + _socket.Shutdown(how); + } + catch (SocketException ex) + { + // TODO: log as warning + DiagnosticAbstraction.Log("Failure shutting down socket: " + ex); + } } } diff --git a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs index d09d78b6..7d731b9e 100644 --- a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs @@ -26,8 +26,20 @@ namespace Renci.SshNet.Channels /// The remote channel number. /// The window size of the remote party. /// The maximum size of a data packet that we can send to the remote party. - internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize) + internal ChannelForwardedTcpip(ISession session, + uint localChannelNumber, + uint localWindowSize, + uint localPacketSize, + uint remoteChannelNumber, + uint remoteWindowSize, + uint remotePacketSize) + : base(session, + localChannelNumber, + localWindowSize, + localPacketSize, + remoteChannelNumber, + remoteWindowSize, + remotePacketSize) { } @@ -116,7 +128,15 @@ namespace Renci.SshNet.Channels if (!socket.IsConnected()) return; - socket.Shutdown(how); + try + { + socket.Shutdown(how); + } + catch (SocketException ex) + { + // TODO: log as warning + DiagnosticAbstraction.Log("Failure shutting down socket: " + ex); + } } } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 812c0729..2dcce2b1 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1796,8 +1796,8 @@ namespace Renci.SshNet } catch (SocketException ex) { - // TODO: log as info or debug - DiagnosticAbstraction.Log("Failure shutting down socket or clearing read buffer: " + ex); + // TODO: log as warning + DiagnosticAbstraction.Log("Failure shutting down socket: " + ex); } }