Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib: Fixed epoll loop timeout bug.
[ashd.git]
/
lib
/
mtio.c
diff --git
a/lib/mtio.c
b/lib/mtio.c
index
367c61d
..
b594f0d
100644
(file)
--- a/
lib/mtio.c
+++ b/
lib/mtio.c
@@
-63,7
+63,8
@@
static int regfd(struct blocker *bl)
{
struct blocker *o;
struct epoll_event evd;
{
struct blocker *o;
struct epoll_event evd;
-
+
+ memset(&evd, 0, sizeof(evd));
evd.events = 0;
if(bl->ev & EV_READ)
evd.events |= EPOLLIN;
evd.events = 0;
if(bl->ev & EV_READ)
evd.events |= EPOLLIN;
@@
-124,6
+125,7
@@
static void remfd(struct blocker *bl)
if(epoll_ctl(epfd, EPOLL_CTL_DEL, bl->fd, NULL))
flog(LOG_ERR, "epoll_del on fd %i: %s", bl->fd, strerror(errno));
} else {
if(epoll_ctl(epfd, EPOLL_CTL_DEL, bl->fd, NULL))
flog(LOG_ERR, "epoll_del on fd %i: %s", bl->fd, strerror(errno));
} else {
+ memset(&evd, 0, sizeof(evd));
evd.events = 0;
evd.data.fd = bl->fd;
for(o = fdlist[bl->fd]; o; o = o->n2) {
evd.events = 0;
evd.data.fd = bl->fd;
for(o = fdlist[bl->fd]; o; o = o->n2) {
@@
-174,7
+176,7
@@
void ioloop(void)
{
struct blocker *bl, *nbl;
struct epoll_event evr[16];
{
struct blocker *bl, *nbl;
struct epoll_event evr[16];
- int i, fd, nev, ev;
+ int i, fd, nev, ev
, toval
;
time_t now, timeout;
epfd = epoll_create(128);
time_t now, timeout;
epfd = epoll_create(128);
@@
-190,7
+192,13
@@
void ioloop(void)
timeout = bl->to;
}
now = time(NULL);
timeout = bl->to;
}
now = time(NULL);
- nev = epoll_wait(epfd, evr, sizeof(evr) / sizeof(*evr), timeout?((timeout - now) * 1000):-1);
+ if(timeout == 0)
+ toval = -1;
+ else if(timeout > now)
+ toval = (timeout - now) * 1000;
+ else
+ toval = 1000;
+ nev = epoll_wait(epfd, evr, sizeof(evr) / sizeof(*evr), toval);
if(nev < 0) {
if(errno != EINTR) {
flog(LOG_CRIT, "ioloop: select errored out: %s", strerror(errno));
if(nev < 0) {
if(errno != EINTR) {
flog(LOG_CRIT, "ioloop: select errored out: %s", strerror(errno));
@@
-200,7
+208,6
@@
void ioloop(void)
}
continue;
}
}
continue;
}
- now = time(NULL);
for(i = 0; i < nev; i++) {
fd = evr[i].data.fd;
ev = 0;
for(i = 0; i < nev; i++) {
fd = evr[i].data.fd;
ev = 0;
@@
-214,10
+221,14
@@
void ioloop(void)
nbl = bl->n2;
if((ev < 0) || (ev & bl->ev))
resume(bl->th, ev);
nbl = bl->n2;
if((ev < 0) || (ev & bl->ev))
resume(bl->th, ev);
- else if((bl->to != 0) && (bl->to <= now))
- resume(bl->th, 0);
}
}
}
}
+ now = time(NULL);
+ for(bl = blockers; bl; bl = nbl) {
+ nbl = bl->n;
+ if((bl->to != 0) && (bl->to <= now))
+ resume(bl->th, 0);
+ }
}
close(epfd);
epfd = -1;
}
close(epfd);
epfd = -1;