I assume you are talking about TCP connections, not UDP.
Are you saying that the listen port (server socket) stops accepting new fresh connections or you're talking about an accepted connection that stops receiving data after a period of inactivity?
If you are talking about an established connection, there may be a timeout problem due to inactivity, in which case using keep alive (uv_tcp_keepalive) should resolve the situation.
If you're talking about the socket that started listening for incoming connections and stops accepting new connections after a while, it seems a little strange, logs if uv_listen's callback (uv_connection_cb) is invoked and what the status value is, or if your application was actually killed by an unhandled signal.
About handling signal errors, you can use uv_signal_start, in addition problably be a good idea handle SIGPIPE (
http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#The_special_problem_of_SIGPIPE)
You can use an approach like this:
int requested_shutdown;
uv_signal_t sig_int;
uv_signal_t sig_term;
void system_signals_start(void) {
signal(SIGPIPE, SIG_IGN);
uv_signal_init(uv_default_loop(), &sig_int);
uv_signal_init(uv_default_loop(), &sig_term);
uv_signal_start(&sig_int, signal_shutdown, SIGINT);
uv_signal_start(&sig_term, signal_shutdown, SIGTERM);
}
void system_signals_stop(void) {
uv_signal_stop(&sig_int);
uv_close((uv_handle_t *)&sig_int, NULL);
uv_signal_stop(&sig_term);
uv_close((uv_handle_t *)&sig_term, NULL);
}
static void signal_shutdown(uv_signal_t *handle, int code) {
fprintf(stderr, "Signal received: %d\n", code);
if ((code == SIGINT) || (code == SIGTERM))
requested_shutdown = 1;
}
void system_shutdown(void) {
system_signals_stop();
...
}
: