summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6f146b5)
Previously we relied on the max_fds argument to register_for_poll
being big enough and allocated an array at startup. But we are going
to want to be more dynamic, so actually do the dynamic array resizing.
We now start with a zero-sized array and increase it as needed.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
LIST_ENTRY(poll_interest) entry;
};
static LIST_HEAD(, poll_interest) reg = LIST_HEAD_INITIALIZER(®);
LIST_ENTRY(poll_interest) entry;
};
static LIST_HEAD(, poll_interest) reg = LIST_HEAD_INITIALIZER(®);
-static int32_t total_nfds=10;
static bool_t finished=False;
static bool_t finished=False;
i->max_nfds=max_nfds;
i->nfds=0;
i->desc=desc;
i->max_nfds=max_nfds;
i->nfds=0;
i->desc=desc;
- assert(total_nfds < INT_MAX - max_nfds);
- total_nfds+=max_nfds;
LIST_INSERT_HEAD(®, i, entry);
return;
}
LIST_INSERT_HEAD(®, i, entry);
return;
}
struct poll_interest *i;
int rv, nfds, remain, idx;
int timeout;
struct poll_interest *i;
int rv, nfds, remain, idx;
int timeout;
- struct pollfd *fds;
-
- fds=safe_malloc(sizeof(*fds)*total_nfds, "run");
+ struct pollfd *fds=0;
+ int allocdfds=0, shortfall=0;
Message(M_NOTICE,"%s [%d]: starting\n",version,secnet_pid);
Message(M_NOTICE,"%s [%d]: starting\n",version,secnet_pid);
i->after(i->state, fds+idx, i->nfds);
idx+=i->nfds;
}
i->after(i->state, fds+idx, i->nfds);
idx+=i->nfds;
}
+ if (shortfall) {
+ allocdfds *= 2;
+ allocdfds += shortfall;
+ fds=safe_realloc_ary(fds,sizeof(*fds),allocdfds, "run");
+ }
+ remain=allocdfds;
+ shortfall=0;
idx=0;
timeout=-1;
LIST_FOREACH(i, ®, entry) {
nfds=remain;
rv=i->before(i->state, fds+idx, &nfds, &timeout);
if (rv!=0) {
idx=0;
timeout=-1;
LIST_FOREACH(i, ®, entry) {
nfds=remain;
rv=i->before(i->state, fds+idx, &nfds, &timeout);
if (rv!=0) {
- /* XXX we need to handle this properly: increase the
- nfds available */
- fatal("run: beforepoll_fn (%s) returns %d",i->desc,rv);
+ if (rv!=ERANGE)
+ fatal("run: beforepoll_fn (%s) returns %d",i->desc,rv);
+ assert(nfds < INT_MAX/4 - shortfall);
+ shortfall += nfds-remain;
+ nfds=0;
+ timeout=0;
}
if (timeout<-1) {
fatal("run: beforepoll_fn (%s) set timeout to %d",
}
if (timeout<-1) {
fatal("run: beforepoll_fn (%s) set timeout to %d",