#include <sys/socket.h>
#include <netdb.h>
#include <poll.h>
+#include <signal.h>
#include <errno.h>
#include <vector>
#include <string>
{
should_stop = true;
+ pthread_kill(worker_thread, SIGHUP);
if (pthread_join(worker_thread, NULL) == -1) {
perror("pthread_join");
exit(1);
pfd.events |= POLLRDHUP;
int nfds = poll(&pfd, 1, 50);
- if (nfds == 0 || (nfds == -1 && errno == EAGAIN)) {
+ if (nfds == 0 || (nfds == -1 && errno == EINTR)) {
continue;
}
if (nfds == -1) {
pfd.events = POLLIN;
int nfds = poll(&pfd, 1, 50);
- if (nfds == 0 || (nfds == -1 && errno == EAGAIN)) {
+ if (nfds == 0 || (nfds == -1 && errno == EINTR)) {
continue;
}
if (nfds == -1) {
int left_to_sleep = parms->stats_interval;
do {
left_to_sleep = sleep(left_to_sleep);
- } while (left_to_sleep > 0);
+ } while (left_to_sleep > 0 && !hupped);
}
return NULL;
}
gettimeofday(&serialize_start, NULL);
if (!stats_file.empty()) {
+ pthread_kill(stats_thread, SIGHUP);
if (pthread_join(stats_thread, NULL) == -1) {
perror("pthread_join");
exit(1);
}
}
+ pthread_kill(acceptor_thread, SIGHUP);
if (pthread_join(acceptor_thread, NULL) == -1) {
perror("pthread_join");
exit(1);
#include <sys/ioctl.h>
#include <sys/epoll.h>
#include <time.h>
+#include <signal.h>
#include <errno.h>
#include <vector>
#include <string>
should_stop = true;
}
+ pthread_kill(worker_thread, SIGHUP);
if (pthread_join(worker_thread, NULL) == -1) {
perror("pthread_join");
exit(1);
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) {
MutexLock lock(&mutex); // We release the mutex between iterations.
- if (should_stop) {
- return;
- }
-
process_queued_data();
for (int i = 0; i < nfds; ++i) {
process_client(to_process[i]);
}
}
+
+ if (should_stop) {
+ return;
+ }
}
}