]> git.sesse.net Git - cubemap/blobdiff - server.cpp
Explicitly SIGHUP threads to kill them out of syscalls when we want to join them...
[cubemap] / server.cpp
index 5c55636668eca819141f44099461ae419c51d997..6e1005e1090ccd851c5690f3f6f4174c6c00f8ab 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/ioctl.h>
 #include <sys/epoll.h>
 #include <time.h>
+#include <signal.h>
 #include <errno.h>
 #include <vector>
 #include <string>
@@ -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;
+               }
        }
 }