Fix exception handling of socket initialization

This commit is contained in:
bibendovsky 2017-05-08 11:44:05 +03:00
parent db13bfa39c
commit 418ed41078

View file

@ -1,3 +1,4 @@
using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
@ -233,13 +234,29 @@ namespace AsterNET.FastAGI
var ipAddress = IPAddress.Parse(address); var ipAddress = IPAddress.Parse(address);
serverSocket = new ServerSocket(port, ipAddress, SocketEncoding); serverSocket = new ServerSocket(port, ipAddress, SocketEncoding);
} }
catch (IOException ex) catch (Exception ex)
{ {
#if LOGGER #if LOGGER
if (ex is IOException)
{
logger.Error("Unable start AGI Server: cannot to bind to " + address + ":" + port + ".", ex); logger.Error("Unable start AGI Server: cannot to bind to " + address + ":" + port + ".", ex);
}
#endif #endif
if (serverSocket != null)
{
serverSocket.Close();
serverSocket = null;
}
pool.Shutdown();
#if LOGGER
logger.Info("AGIServer shut down.");
#endif
throw ex; throw ex;
} }
#if LOGGER #if LOGGER
logger.Info("Listening on " + address + ":" + port + "."); logger.Info("Listening on " + address + ":" + port + ".");
#endif #endif