diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-05-31 06:05:29 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-05-31 06:05:29 +0200 |
commit | 73f7d5048c0e2ad4817ad208de02adee73938ed0 (patch) | |
tree | 1a292a82567eb49d3b0c9a8218d869528a994682 /src/poll.c | |
parent | 6c656c7394bb972e81cd291b0ab126b2e73ce499 (diff) | |
download | fastd-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.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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) |