X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=6e1005e1090ccd851c5690f3f6f4174c6c00f8ab;hp=5c55636668eca819141f44099461ae419c51d997;hb=5ab36b04b0c12058394335e891398c494df513d2;hpb=019b96a9cc6fa2902690e98a2aa033517efef3ed diff --git a/server.cpp b/server.cpp index 5c55636..6e1005e 100644 --- a/server.cpp +++ b/server.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,7 @@ void Server::stop() should_stop = true; } + pthread_kill(worker_thread, SIGHUP); if (pthread_join(worker_thread, NULL) == -1) { perror("pthread_join"); exit(1); @@ -211,6 +213,9 @@ void Server::do_work() for ( ;; ) { int nfds = epoll_wait(epoll_fd, events, EPOLL_MAX_EVENTS, EPOLL_TIMEOUT_MS); if (nfds == -1 && errno == EINTR) { + if (should_stop) { + return; + } continue; } if (nfds == -1) { @@ -220,10 +225,6 @@ void Server::do_work() MutexLock lock(&mutex); // We release the mutex between iterations. - if (should_stop) { - return; - } - process_queued_data(); for (int i = 0; i < nfds; ++i) { @@ -248,6 +249,10 @@ void Server::do_work() process_client(to_process[i]); } } + + if (should_stop) { + return; + } } }