From eff1f08ab881cfeeb574dd332aaf4f42e6c2c450 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Tue, 7 Mar 2017 10:35:50 +0200 Subject: [PATCH] SocketUtils.ReleaseSocket: Improved exception handling --- SMBLibrary/Utilities/SocketUtils.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/SMBLibrary/Utilities/SocketUtils.cs b/SMBLibrary/Utilities/SocketUtils.cs index 60ab8b1..f4dcd92 100644 --- a/SMBLibrary/Utilities/SocketUtils.cs +++ b/SMBLibrary/Utilities/SocketUtils.cs @@ -1,3 +1,9 @@ +/* Copyright (C) 2012-2017 Tal Aloni . All rights reserved. + * + * You can redistribute this program and/or modify it under the terms of + * the GNU Lesser Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + */ using System; using System.Collections.Generic; using System.Net; @@ -36,11 +42,15 @@ namespace Utilities { if (socket.Connected) { - socket.Shutdown(SocketShutdown.Both); try { + socket.Shutdown(SocketShutdown.Both); socket.Disconnect(false); } + catch (ObjectDisposedException) + { + return; + } catch (SocketException) { } }