Merge pull request #104 from bibendovsky/fix/fastagi_start2

Clean up on socket initialization error
This commit is contained in:
Ben Merrills 2017-10-26 09:46:38 +01:00 committed by GitHub
commit b3cd107043

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
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 #endif
if (serverSocket != null)
{
serverSocket.Close();
serverSocket = null;
}
pool.Shutdown();
#if LOGGER
logger.Info("AGI Server 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
@ -287,7 +304,7 @@ namespace AsterNET.FastAGI
serverSocket = null; serverSocket = null;
pool.Shutdown(); pool.Shutdown();
#if LOGGER #if LOGGER
logger.Info("AGIServer shut down."); logger.Info("AGI Server shut down.");
#endif #endif
} }
} }