summaryrefslogtreecommitdiffstats
path: root/src/poll.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-31 06:05:29 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-31 06:05:29 +0200
commit73f7d5048c0e2ad4817ad208de02adee73938ed0 (patch)
tree1a292a82567eb49d3b0c9a8218d869528a994682 /src/poll.c
parent6c656c7394bb972e81cd291b0ab126b2e73ce499 (diff)
downloadfastd-73f7d5048c0e2ad4817ad208de02adee73938ed0.tar
fastd-73f7d5048c0e2ad4817ad208de02adee73938ed0.zip
Unblock signals only during poll/epoll wait
If signals are normally blocked, we can avoid a lot of EINTR handling.
Diffstat (limited to 'src/poll.c')
-rw-r--r--src/poll.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/poll.c b/src/poll.c
index a2d206b..f05a345 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -34,6 +34,10 @@
#include "async.h"
#include "peer.h"
+#include <pthread.h>
+#include <signal.h>
+
+
#ifdef USE_EPOLL
#include <sys/epoll.h>
@@ -129,6 +133,10 @@ void fastd_poll_handle(void) {
if (timeout < 0 || timeout > maintenance_timeout)
timeout = maintenance_timeout;
+ sigset_t set, oldset;
+ sigemptyset(&set);
+ pthread_sigmask(SIG_SETMASK, &set, &oldset);
+
struct epoll_event events[16];
int ret = epoll_wait(ctx.epoll_fd, events, 16, timeout);
if (ret < 0) {
@@ -138,6 +146,8 @@ void fastd_poll_handle(void) {
exit_errno("epoll_wait");
}
+ pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+
fastd_update_time();
size_t i;
@@ -243,6 +253,10 @@ void fastd_poll_handle(void) {
if (VECTOR_LEN(ctx.pollfds) != 2 + ctx.n_socks + VECTOR_LEN(ctx.peers))
exit_bug("fd count mismatch");
+ sigset_t set, oldset;
+ sigemptyset(&set);
+ pthread_sigmask(SIG_SETMASK, &set, &oldset);
+
int ret = poll(VECTOR_DATA(ctx.pollfds), VECTOR_LEN(ctx.pollfds), timeout);
if (ret < 0) {
if (errno == EINTR)
@@ -251,6 +265,8 @@ void fastd_poll_handle(void) {
exit_errno("poll");
}
+ pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+
fastd_update_time();
if (VECTOR_INDEX(ctx.pollfds, 0).revents & POLLIN)