[Asterisk-java-devel] Regarding accept() call IOException
Brought to you by:
srt
|
From: Shivram u <shi...@gm...> - 2006-08-11 07:26:52
|
Hi,
In fastagi/DefaultAGIServer.java i had a question w.r.t exception handling
of the accept call.
How does java work in the statement
while ((socket = serverSocket.accept()) != null)
I assume that it throw an exception and gets handled by the exception
handler. rather than hitting the check for socket being null.
If my assumption is correct, we hit the catch and then the finally statement
where we close the server socket.
But shouldnt we just wait for the next client connection when the accept
call fails
Something like
While (1)
{
try {
socket = accept();
}
catch IOException()
{
continue; /* loop back for the next client connection */
}
Below is the piece of code in question
Best Regards,
Shivram U
try
{
while ((socket = serverSocket.accept()) != null)
{
logger.info("Received connection.");
connectionHandler = new AGIConnectionHandler(socket,
mappingStrategy);
pool.addJob(connectionHandler);
}
}
catch (IOException e)
{
// swallow only if shutdown
if (!die)
{
logger.error("IOException while waiting for connections.",
e);
throw e;
}
}
finally
{
if (serverSocket != null)
{
try
{
serverSocket.close();
}
catch (IOException e)
{
// swallow
}
}
serverSocket = null;
pool.shutdown();
logger.info("AGIServer shut down.");
}
|