summaryrefslogtreecommitdiff
path: root/src/fdevent_select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fdevent_select.c')
-rw-r--r--src/fdevent_select.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/fdevent_select.c b/src/fdevent_select.c
index 4a32420..2e23dce 100644
--- a/src/fdevent_select.c
+++ b/src/fdevent_select.c
@@ -1,5 +1,6 @@
#include "fdevent.h"
#include "buffer.h"
+#include "log.h"
#include <sys/time.h>
#include <sys/types.h>
@@ -33,7 +34,7 @@ static int fdevent_select_event_del(fdevents *ev, int fde_ndx, int fd) {
return -1;
}
-static int fdevent_select_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
+static int fdevent_select_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
UNUSED(fde_ndx);
/* we should be protected by max-fds, but you never know */
@@ -41,11 +42,13 @@ static int fdevent_select_event_add(fdevents *ev, int fde_ndx, int fd, int event
if (events & FDEVENT_IN) {
FD_SET(fd, &(ev->select_set_read));
- FD_CLR(fd, &(ev->select_set_write));
+ } else {
+ FD_CLR(fd, &(ev->select_set_read));
}
if (events & FDEVENT_OUT) {
- FD_CLR(fd, &(ev->select_set_read));
FD_SET(fd, &(ev->select_set_write));
+ } else {
+ FD_CLR(fd, &(ev->select_set_write));
}
FD_SET(fd, &(ev->select_set_error));
@@ -95,12 +98,12 @@ static int fdevent_select_event_next_fdndx(fdevents *ev, int ndx) {
i = (ndx < 0) ? 0 : ndx + 1;
for (; i < ev->select_max_fd + 1; i++) {
- if (FD_ISSET(i, &(ev->select_read))) break;
- if (FD_ISSET(i, &(ev->select_write))) break;
- if (FD_ISSET(i, &(ev->select_error))) break;
+ if (FD_ISSET(i, &(ev->select_read))) return i;
+ if (FD_ISSET(i, &(ev->select_write))) return i;
+ if (FD_ISSET(i, &(ev->select_error))) return i;
}
- return i;
+ return -1;
}
int fdevent_select_init(fdevents *ev) {
@@ -112,7 +115,7 @@ int fdevent_select_init(fdevents *ev) {
SET(poll);
SET(event_del);
- SET(event_add);
+ SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);