summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-06 00:40:48 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-06 00:41:15 +0200
commit76becb4729581abb27dc23d9909bd390553de7aa (patch)
tree416ba6eb7ee8a5a8c310af099aeab156292395c1
parent2561266c156a1f63ed85fe2865ac607507ae4cef (diff)
downloadfastd-76becb4729581abb27dc23d9909bd390553de7aa.tar
fastd-76becb4729581abb27dc23d9909bd390553de7aa.zip
Fix poll initialization on systems without epoll
-rw-r--r--src/poll.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/poll.c b/src/poll.c
index f585cfb..3021399 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -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,