1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-01-19 03:52:52 +00:00

io: remove outer do {} while loops for epoll/kqueue/devpoll backends

simplifies things a bit. io_dispatch() is called repeatedly from the
main loop.
This commit is contained in:
Florian Westphal 2012-01-24 21:57:23 +01:00
parent 871760583c
commit c7dd5ea0ba

View File

@ -160,22 +160,18 @@ io_dispatch_devpoll(struct timeval *tv)
{
struct dvpoll dvp;
time_t sec = tv->tv_sec * 1000;
int i, total, ret, timeout = tv->tv_usec + sec;
int i, ret, timeout = tv->tv_usec + sec;
short what;
struct pollfd p[100];
if (timeout < 0)
timeout = 1000;
total = 0;
do {
dvp.dp_timeout = timeout;
dvp.dp_nfds = 100;
dvp.dp_fds = p;
ret = ioctl(io_masterfd, DP_POLL, &dvp);
total += ret;
if (ret <= 0)
return total;
for (i=0; i < ret ; i++) {
what = 0;
if (p[i].revents & (POLLIN|POLLPRI))
@ -190,9 +186,8 @@ io_dispatch_devpoll(struct timeval *tv)
}
io_docallback(p[i].fd, what);
}
} while (ret == 100);
return total;
return ret;
}
@ -462,18 +457,14 @@ static int
io_dispatch_epoll(struct timeval *tv)
{
time_t sec = tv->tv_sec * 1000;
int i, total = 0, ret, timeout = tv->tv_usec + sec;
int i, ret, timeout = tv->tv_usec + sec;
struct epoll_event epoll_ev[100];
short type;
if (timeout < 0)
timeout = 1000;
do {
ret = epoll_wait(io_masterfd, epoll_ev, 100, timeout);
total += ret;
if (ret <= 0)
return total;
for (i = 0; i < ret; i++) {
type = 0;
@ -489,10 +480,7 @@ io_dispatch_epoll(struct timeval *tv)
io_docallback(epoll_ev[i].data.fd, type);
}
timeout = 0;
} while (ret == 100);
return total;
return ret;
}
static void
@ -576,7 +564,7 @@ io_event_change_kqueue(int fd, short what, const int action)
static int
io_dispatch_kqueue(struct timeval *tv)
{
int i, total = 0, ret;
int i, ret;
struct kevent kev[100];
struct kevent *newevents;
struct timespec ts;
@ -584,7 +572,6 @@ io_dispatch_kqueue(struct timeval *tv)
ts.tv_sec = tv->tv_sec;
ts.tv_nsec = tv->tv_usec * 1000;
do {
newevents_len = (int) array_length(&io_evcache, sizeof (struct kevent));
newevents = (newevents_len > 0) ? array_start(&io_evcache) : NULL;
assert(newevents_len >= 0);
@ -593,10 +580,6 @@ io_dispatch_kqueue(struct timeval *tv)
if (newevents && ret != -1)
array_trunc(&io_evcache);
total += ret;
if (ret <= 0)
return total;
for (i = 0; i < ret; i++) {
io_debug("dispatch_kqueue: fd, kev.flags", (int)kev[i].ident, kev[i].flags);
if (kev[i].flags & (EV_EOF|EV_ERROR)) {
@ -623,11 +606,8 @@ io_dispatch_kqueue(struct timeval *tv)
break;
}
}
ts.tv_sec = 0;
ts.tv_nsec = 0;
} while (ret == 100);
return total;
return ret;
}
static void