diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-06 00:40:48 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-06 00:41:15 +0200 |
commit | 76becb4729581abb27dc23d9909bd390553de7aa (patch) | |
tree | 416ba6eb7ee8a5a8c310af099aeab156292395c1 | |
parent | 2561266c156a1f63ed85fe2865ac607507ae4cef (diff) | |
download | fastd-76becb4729581abb27dc23d9909bd390553de7aa.tar fastd-76becb4729581abb27dc23d9909bd390553de7aa.zip |
Fix poll initialization on systems without epoll
-rw-r--r-- | src/poll.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -196,7 +196,7 @@ void fastd_poll_handle(void) { #else void fastd_poll_init(void) { - VECTOR_RESIZE(ctx.pollfds, 3 + ctx.n_socks); + VECTOR_RESIZE(ctx.pollfds, 3 + ctx.n_socks + VECTOR_LEN(ctx.peers)); VECTOR_INDEX(ctx.pollfds, 0) = (struct pollfd) { .fd = -1, @@ -221,7 +221,7 @@ void fastd_poll_init(void) { }; size_t i; - for (i = 0; i < ctx.n_socks; i++) { + for (i = 0; i < ctx.n_socks + VECTOR_LEN(ctx.peers); i++) { VECTOR_INDEX(ctx.pollfds, 3+i) = (struct pollfd) { .fd = -1, .events = POLLIN, @@ -244,6 +244,9 @@ void fastd_poll_set_fd_sock(size_t i) { } void fastd_poll_set_fd_peer(size_t i) { + if (!VECTOR_LEN(ctx.pollfds)) + exit_bug("fastd_poll_set_fd_peer: polling not initialized yet"); + fastd_peer_t *peer = VECTOR_INDEX(ctx.peers, i); if (!peer->sock || !fastd_peer_is_socket_dynamic(peer)) @@ -253,6 +256,10 @@ void fastd_poll_set_fd_peer(size_t i) { } void fastd_poll_add_peer(void) { + if (!VECTOR_LEN(ctx.pollfds)) + /* Polling is not initialized yet */ + return; + struct pollfd pollfd = { .fd = -1, .events = POLLIN, |