apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Vieiro <anto...@antonioshome.net>
Subject Graceful server shutdown?
Date Tue, 05 Jul 2011 09:45:41 GMT
Hi all,

I'm building a small server on top of the APR library. Everything is
working fine but for the shutdown procedure.

My server opens a server socket and blocks on a loop waiting for new
connections through apr_socket_accept .

I've added a listener for signals (using apr_signal) so whenever I get
a SIGINT I want to close the server. I don't know how to proceed,
though, and I'd appreciate any suggestions. I'm thinking of one of the
two following options:

a) Shall I invoke apr_socket_close on the server socket from the
SIGINT handler? If so, is this thread safe? (I mean, invoking
apr_socket_close from the signal handler while the server is
apr_socket_accept-ing)? Which return code should I expect from
apr_socket_accept if apr_socket_close is invoked? (these return codes
are not documented).

b) Shall I set a "keep-running" flag (using mutexes, i.e, a
synchronized flag) for shutdown on the SIGINT handler? If so I would
need to check the flag periodically in my server loop, and make the
server socket timeout, right? In my loop I would detect timeouts from
apr_socket_accept and check the flag, and invoke accept again if the
server is to be kept running.

On both cases I imagine the server cleanup (apr_pool_destroy) should
be performed after the server loop, and not in the signal handler,

Thanks in advance,

View raw message