From 18f7d1edd393823e3872e9e88db2dcc37ac005e1 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Thu, 10 Nov 2011 15:34:19 +0100 Subject: [PATCH] refactored signal_wait --- signal.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ uwsgi.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/signal.c b/signal.c index 9718b060..b7b11ba5 100644 --- a/signal.c +++ b/signal.c @@ -301,3 +301,51 @@ void uwsgi_route_signal(uint8_t sig) { uwsgi_log("^^^ UNSUPPORTED SIGNAL TARGET: %s ^^^\n", use->receiver); } } + +uint8_t uwsgi_signal_wait(int signum) { + + int wait_for_specific_signal = 0; + uint8_t uwsgi_signal = 0; + uint8_t received_signal; + int ret; + struct pollfd pfd[2]; + + if (signum > -1) { + wait_for_specific_signal = 1; + } + + pfd[0].fd = uwsgi.signal_socket; + pfd[0].events = POLLIN; + pfd[1].fd = uwsgi.my_signal_socket; + pfd[1].events = POLLIN; +cycle: + ret = poll(pfd, 2, -1); + if (ret > 0) { + if (pfd[0].revents == POLLIN) { + if (read(uwsgi.signal_socket, &received_signal, 1) != 1) { + uwsgi_error("read()"); + } + else { + (void)uwsgi_signal_handler(received_signal); + if (wait_for_specific_signal) { + if (received_signal != uwsgi_signal) goto cycle; + } + } + } + if (pfd[1].revents == POLLIN) { + if (read(uwsgi.my_signal_socket, &received_signal, 1) != 1) { + uwsgi_error("read()"); + } + else { + (void)uwsgi_signal_handler(received_signal); + if (wait_for_specific_signal) { + if (received_signal != uwsgi_signal) goto cycle; + } + } + } + + } + + return received_signal; +} + diff --git a/uwsgi.h b/uwsgi.h index eafea987..4c14fb35 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2447,6 +2447,8 @@ struct uwsgi_subscribe_node *uwsgi_get_subscribe_node(struct uwsgi_subscribe_slo void uwsgi_remove_subscribe_node(struct uwsgi_subscribe_slot **, struct uwsgi_subscribe_node *); struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slot **, struct uwsgi_subscribe_req *, int); +uint8_t uwsgi_signal_wait(int); + #ifdef UWSGI_CAP void uwsgi_build_cap(char *); #endif