X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=acceptor.cpp;h=3172c73b80a1821e0973e08c267f6f8ccae74c10;hp=2abfa5220064ec47efb8d40c41d3ad9ceed6a79d;hb=71fc5575037bead8b6e927a1fffd199e4fc4514b;hpb=ba03a3ed19cc8b02d4bb198edfd1c8bee9f28e35 diff --git a/acceptor.cpp b/acceptor.cpp index 2abfa52..3172c73 100644 --- a/acceptor.cpp +++ b/acceptor.cpp @@ -12,11 +12,11 @@ #include "log.h" #include "serverpool.h" #include "state.pb.h" -#include "util.h" using namespace std; extern ServerPool *servers; +extern volatile bool hupped; int create_server_socket(int port, SocketType socket_type) { @@ -93,13 +93,32 @@ AcceptorProto Acceptor::serialize() const void Acceptor::close_socket() { - safe_close(server_sock); + int ret; + do { + ret = close(server_sock); + } while (ret == -1 && errno == EINTR); + + if (ret == -1) { + log_perror("close"); + } } void Acceptor::do_work() { - while (!should_stop()) { - if (!wait_for_activity(server_sock, POLLIN, NULL)) { + while (!hupped) { + // Since we are non-blocking, we need to wait for the right state first. + // Wait up to 50 ms, then check hupped. + pollfd pfd; + pfd.fd = server_sock; + pfd.events = POLLIN; + + int nfds = poll(&pfd, 1, 50); + if (nfds == 0 || (nfds == -1 && errno == EINTR)) { + continue; + } + if (nfds == -1) { + log_perror("poll"); + usleep(100000); continue; }