poll: Abolish max_nfds
[secnet] / secnet.c
index 7a9d3f0..4520b3e 100644 (file)
--- a/secnet.c
+++ b/secnet.c
@@ -39,7 +39,6 @@ struct poll_interest {
     beforepoll_fn *before;
     afterpoll_fn *after;
     void *state;
-    int32_t max_nfds;
     int32_t nfds;
     cstring_t desc;
     LIST_ENTRY(poll_interest) entry;
@@ -227,7 +226,7 @@ static void setup(dict_t *config)
 }
 
 void register_for_poll(void *st, beforepoll_fn *before,
-                      afterpoll_fn *after, int32_t max_nfds, cstring_t desc)
+                      afterpoll_fn *after, cstring_t desc)
 {
     struct poll_interest *i;
 
@@ -235,7 +234,6 @@ void register_for_poll(void *st, beforepoll_fn *before,
     i->before=before;
     i->after=after;
     i->state=st;
-    i->max_nfds=max_nfds;
     i->nfds=0;
     i->desc=desc;
     LIST_INSERT_HEAD(&reg, i, entry);
@@ -291,7 +289,7 @@ uint64_t now_global;
 static void run(void)
 {
     struct poll_interest *i;
-    int rv, nfds, remain, idx;
+    int rv, nfds, idx;
     int timeout;
     struct pollfd *fds=0;
     int allocdfds=0, shortfall=0;
@@ -320,11 +318,11 @@ static void run(void)
            allocdfds += shortfall;
            fds=safe_realloc_ary(fds,sizeof(*fds),allocdfds, "run");
        }
-       remain=allocdfds;
        shortfall=0;
        idx=0;
        timeout=-1;
        LIST_FOREACH(i, &reg, entry) {
+           int remain=allocdfds-idx;
            nfds=remain;
            rv=i->before(i->state, fds+idx, &nfds, &timeout);
            if (rv!=0) {
@@ -340,7 +338,6 @@ static void run(void)
                      i->desc,timeout);
            }
            idx+=nfds;
-           remain-=nfds;
            i->nfds=nfds;
        }
        do {