SocketUtils.ReleaseSocket: Improved exception handling

This commit is contained in:
Tal Aloni 2017-03-07 10:35:50 +02:00
parent 512f03f77f
commit eff1f08ab8

View file

@ -1,3 +1,9 @@
/* Copyright (C) 2012-2017 Tal Aloni <tal.aloni.il@gmail.com>. 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)
{ }
}