From 418ed41078375bc8b1acce1b6c8a47ee96e8d841 Mon Sep 17 00:00:00 2001 From: bibendovsky Date: Mon, 8 May 2017 11:44:05 +0300 Subject: [PATCH 1/2] Fix exception handling of socket initialization --- .../Asterisk.NET/FastAGI/AsteriskFastAGI.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs b/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs index 8e7decf..a72322a 100644 --- a/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs +++ b/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Net; using System.Text; @@ -233,13 +234,29 @@ namespace AsterNET.FastAGI var ipAddress = IPAddress.Parse(address); serverSocket = new ServerSocket(port, ipAddress, SocketEncoding); } - catch (IOException ex) + catch (Exception ex) { #if LOGGER - logger.Error("Unable start AGI Server: cannot to bind to " + address + ":" + port + ".", ex); + if (ex is IOException) + { + logger.Error("Unable start AGI Server: cannot to bind to " + address + ":" + port + ".", ex); + } #endif + + if (serverSocket != null) + { + serverSocket.Close(); + serverSocket = null; + } + + pool.Shutdown(); +#if LOGGER + logger.Info("AGIServer shut down."); +#endif + throw ex; } + #if LOGGER logger.Info("Listening on " + address + ":" + port + "."); #endif From 53e521c7ee2a3d62e75d672a495069cc985871c0 Mon Sep 17 00:00:00 2001 From: Boris Bendovsky Date: Wed, 27 Sep 2017 15:08:18 +0300 Subject: [PATCH 2/2] Fix typo --- Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs b/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs index a72322a..c200a7c 100644 --- a/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs +++ b/Asterisk.2013/Asterisk.NET/FastAGI/AsteriskFastAGI.cs @@ -251,7 +251,7 @@ namespace AsterNET.FastAGI pool.Shutdown(); #if LOGGER - logger.Info("AGIServer shut down."); + logger.Info("AGI Server shut down."); #endif throw ex; @@ -304,7 +304,7 @@ namespace AsterNET.FastAGI serverSocket = null; pool.Shutdown(); #if LOGGER - logger.Info("AGIServer shut down."); + logger.Info("AGI Server shut down."); #endif } }