MEDIUM: fd: remove the EV_FD_COND_* primitives
These primitives were initially introduced so that callers were able to
conditionally set/disable polling on a file descriptor and check in return
what the state was. It's been long since we last had an "if" on this, and
all pollers' functions were the same for cond_* and their systematic
counter parts, except that this required a check and a specific return
value that are not always necessary.
So let's simplify the FD API by removing this now unused distinction and
by making all specific functions return void.
diff --git a/src/ev_epoll.c b/src/ev_epoll.c
index 63782d3..6c8408b 100644
--- a/src/ev_epoll.c
+++ b/src/ev_epoll.c
@@ -147,7 +147,7 @@
ptr->prev = old_evt;
}
-REGPRM2 static int __fd_set(const int fd, int dir)
+REGPRM2 static void __fd_set(const int fd, int dir)
{
uint32_t ofs = FD2OFS(fd);
uint32_t dmsk = DIR2MSK(dir);
@@ -156,15 +156,14 @@
old_evt = fd_evts[ofs] >> FD2BIT(fd);
old_evt &= 3;
if (unlikely(old_evt & dmsk))
- return 0;
+ return;
alloc_chg_list(fd, old_evt);
dmsk <<= FD2BIT(fd);
fd_evts[ofs] |= dmsk;
- return 1;
}
-REGPRM2 static int __fd_clr(const int fd, int dir)
+REGPRM2 static void __fd_clr(const int fd, int dir)
{
uint32_t ofs = FD2OFS(fd);
uint32_t dmsk = DIR2MSK(dir);
@@ -173,12 +172,11 @@
old_evt = fd_evts[ofs] >> FD2BIT(fd);
old_evt &= 3;
if (unlikely(!(old_evt & dmsk)))
- return 0;
+ return;
alloc_chg_list(fd, old_evt);
dmsk <<= FD2BIT(fd);
fd_evts[ofs] &= ~dmsk;
- return 1;
}
REGPRM1 static void __fd_rem(int fd)
@@ -190,7 +188,6 @@
alloc_chg_list(fd, 0);
fd_evts[ofs] &= ~FD2MSK(fd);
- return;
}
/*
@@ -206,7 +203,6 @@
ptr->prev = 0;
chg_ptr[fd] = NULL;
}
- return;
}
/*
@@ -399,8 +395,8 @@
p->fork = _do_fork;
p->is_set = __fd_is_set;
- p->cond_s = p->set = __fd_set;
- p->cond_c = p->clr = __fd_clr;
+ p->set = __fd_set;
+ p->clr = __fd_clr;
p->rem = __fd_rem;
p->clo = __fd_clo;
}
diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c
index 3d12e36..4bfbf1b 100644
--- a/src/ev_kqueue.c
+++ b/src/ev_kqueue.c
@@ -60,24 +60,22 @@
return FD_ISSET(fd, fd_evts[dir]);
}
-REGPRM2 static int __fd_set(const int fd, int dir)
+REGPRM2 static void __fd_set(const int fd, int dir)
{
/* if the value was set, do nothing */
if (FD_ISSET(fd, fd_evts[dir]))
- return 0;
+ return;
FD_SET(fd, fd_evts[dir]);
EV_SET(kev, fd, dir2filt[dir], EV_ADD, 0, 0, NULL);
kevent(kqueue_fd, kev, 1, NULL, 0, NULL);
- return 1;
}
-REGPRM2 static int __fd_clr(const int fd, int dir)
+REGPRM2 static void __fd_clr(const int fd, int dir)
{
if (!kqev_del(kev, fd, dir))
- return 0;
+ return;
kevent(kqueue_fd, kev, 1, NULL, 0, NULL);
- return 1;
}
REGPRM1 static void __fd_rem(int fd)
@@ -275,8 +273,8 @@
p->fork = _do_fork;
p->is_set = __fd_is_set;
- p->cond_s = p->set = __fd_set;
- p->cond_c = p->clr = __fd_clr;
+ p->set = __fd_set;
+ p->clr = __fd_clr;
p->rem = __fd_rem;
p->clo = __fd_clo;
}
diff --git a/src/ev_poll.c b/src/ev_poll.c
index cb210f7..f72dfe2 100644
--- a/src/ev_poll.c
+++ b/src/ev_poll.c
@@ -43,34 +43,14 @@
return FD_ISSET(fd, fd_evts[dir]);
}
-REGPRM2 static int __fd_set(const int fd, int dir)
+REGPRM2 static void __fd_set(const int fd, int dir)
{
FD_SET(fd, fd_evts[dir]);
- return 0;
}
-REGPRM2 static int __fd_clr(const int fd, int dir)
+REGPRM2 static void __fd_clr(const int fd, int dir)
{
FD_CLR(fd, fd_evts[dir]);
- return 0;
-}
-
-REGPRM2 static int __fd_cond_s(const int fd, int dir)
-{
- int ret;
- ret = !FD_ISSET(fd, fd_evts[dir]);
- if (ret)
- FD_SET(fd, fd_evts[dir]);
- return ret;
-}
-
-REGPRM2 static int __fd_cond_c(const int fd, int dir)
-{
- int ret;
- ret = FD_ISSET(fd, fd_evts[dir]);
- if (ret)
- FD_CLR(fd, fd_evts[dir]);
- return ret;
}
REGPRM1 static void __fd_rem(const int fd)
@@ -252,8 +232,6 @@
p->set = __fd_set;
p->clr = __fd_clr;
p->clo = p->rem = __fd_rem;
- p->cond_s = __fd_cond_s;
- p->cond_c = __fd_cond_c;
}
diff --git a/src/ev_select.c b/src/ev_select.c
index c5d3936..cf45262 100644
--- a/src/ev_select.c
+++ b/src/ev_select.c
@@ -40,34 +40,14 @@
return FD_ISSET(fd, fd_evts[dir]);
}
-REGPRM2 static int __fd_set(const int fd, int dir)
+REGPRM2 static void __fd_set(const int fd, int dir)
{
FD_SET(fd, fd_evts[dir]);
- return 0;
}
-REGPRM2 static int __fd_clr(const int fd, int dir)
+REGPRM2 static void __fd_clr(const int fd, int dir)
{
FD_CLR(fd, fd_evts[dir]);
- return 0;
-}
-
-REGPRM2 static int __fd_cond_s(const int fd, int dir)
-{
- int ret;
- ret = !FD_ISSET(fd, fd_evts[dir]);
- if (ret)
- FD_SET(fd, fd_evts[dir]);
- return ret;
-}
-
-REGPRM2 static int __fd_cond_c(const int fd, int dir)
-{
- int ret;
- ret = FD_ISSET(fd, fd_evts[dir]);
- if (ret)
- FD_CLR(fd, fd_evts[dir]);
- return ret;
}
REGPRM1 static void __fd_rem(int fd)
@@ -249,8 +229,6 @@
p->set = __fd_set;
p->clr = __fd_clr;
p->clo = p->rem = __fd_rem;
- p->cond_s = __fd_cond_s;
- p->cond_c = __fd_cond_c;
}
diff --git a/src/ev_sepoll.c b/src/ev_sepoll.c
index 5d93bf2..62ee115 100644
--- a/src/ev_sepoll.c
+++ b/src/ev_sepoll.c
@@ -215,7 +215,7 @@
* Don't worry about the strange constructs in __fd_set/__fd_clr, they are
* designed like this in order to reduce the number of jumps (verified).
*/
-REGPRM2 static int __fd_set(const int fd, int dir)
+REGPRM2 static void __fd_set(const int fd, int dir)
{
unsigned int i;
@@ -229,15 +229,14 @@
if (i != FD_EV_STOP) {
if (unlikely(i != FD_EV_IDLE))
- return 0;
+ return;
// switch to SPEC state and allocate a SPEC entry.
alloc_spec_entry(fd);
}
fdtab[fd].spec.e ^= (unsigned int)(FD_EV_IN_SL << dir);
- return 1;
}
-REGPRM2 static int __fd_clr(const int fd, int dir)
+REGPRM2 static void __fd_clr(const int fd, int dir)
{
unsigned int i;
@@ -251,7 +250,7 @@
if (i != FD_EV_SPEC) {
if (unlikely(i != FD_EV_WAIT))
- return 0;
+ return;
// switch to STOP state
/* We will create a queue entry for this one because we want to
* process it later in order to merge it with other events on
@@ -260,7 +259,6 @@
alloc_spec_entry(fd);
}
fdtab[fd].spec.e ^= (unsigned int)(FD_EV_IN_SL << dir);
- return 1;
}
/* normally unused */
@@ -593,8 +591,8 @@
p->fork = _do_fork;
p->is_set = __fd_is_set;
- p->cond_s = p->set = __fd_set;
- p->cond_c = p->clr = __fd_clr;
+ p->set = __fd_set;
+ p->clr = __fd_clr;
p->rem = __fd_rem;
p->clo = __fd_clo;
}
diff --git a/src/sock_raw.c b/src/sock_raw.c
index 8136d60..1532e76 100644
--- a/src/sock_raw.c
+++ b/src/sock_raw.c
@@ -793,7 +793,7 @@
if (!(si->flags & SI_FL_WAIT_ROOM)) {
if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL)
si->flags |= SI_FL_WAIT_ROOM;
- EV_FD_COND_C(fd, DIR_RD);
+ EV_FD_CLR(fd, DIR_RD);
ib->rex = TICK_ETERNITY;
}
}
@@ -804,7 +804,7 @@
* have updated it if there has been a completed I/O.
*/
si->flags &= ~SI_FL_WAIT_ROOM;
- EV_FD_COND_S(fd, DIR_RD);
+ EV_FD_SET(fd, DIR_RD);
if (!(ib->flags & (BF_READ_NOEXP|BF_DONT_READ)) && !tick_isset(ib->rex))
ib->rex = tick_add_ifset(now_ms, ib->rto);
}
@@ -818,7 +818,7 @@
if (!(si->flags & SI_FL_WAIT_DATA)) {
if ((ob->flags & (BF_FULL|BF_HIJACK|BF_SHUTW_NOW)) == 0)
si->flags |= SI_FL_WAIT_DATA;
- EV_FD_COND_C(fd, DIR_WR);
+ EV_FD_CLR(fd, DIR_WR);
ob->wex = TICK_ETERNITY;
}
}
@@ -829,7 +829,7 @@
* have updated it if there has been a completed I/O.
*/
si->flags &= ~SI_FL_WAIT_DATA;
- EV_FD_COND_S(fd, DIR_WR);
+ EV_FD_SET(fd, DIR_WR);
if (!tick_isset(ob->wex)) {
ob->wex = tick_add_ifset(now_ms, ob->wto);
if (tick_isset(ib->rex) && !(si->flags & SI_FL_INDEP_STR)) {
@@ -870,12 +870,12 @@
/* stop reading */
if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL)
si->flags |= SI_FL_WAIT_ROOM;
- EV_FD_COND_C(si_fd(si), DIR_RD);
+ EV_FD_CLR(si_fd(si), DIR_RD);
}
else {
/* (re)start reading */
si->flags &= ~SI_FL_WAIT_ROOM;
- EV_FD_COND_S(si_fd(si), DIR_RD);
+ EV_FD_SET(si_fd(si), DIR_RD);
}
}
@@ -951,7 +951,7 @@
/* Otherwise there are remaining data to be sent in the buffer,
* which means we have to poll before doing so.
*/
- EV_FD_COND_S(si_fd(si), DIR_WR);
+ EV_FD_SET(si_fd(si), DIR_WR);
si->flags &= ~SI_FL_WAIT_DATA;
if (!tick_isset(ob->wex))
ob->wex = tick_add_ifset(now_ms, ob->wto);