Permalink
Browse files

Fixes epoll() backend compilation

  • Loading branch information...
1 parent 78d5edc commit d2e158ea56a5839448cb0e5bea671210c5b3d203 @alobbs alobbs committed Dec 18, 2011
Showing with 45 additions and 30 deletions.
  1. +45 −30 cherokee/fdpoll-epoll.c
View
@@ -80,7 +80,7 @@ _free (cherokee_fdpoll_epoll_t *fdp)
static ret_t
-_add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_epoll_t *fdp, int fd, int mode_rw)
{
struct epoll_event ev;
@@ -94,16 +94,20 @@ _add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
/* Add the new descriptor
*/
ev.data.u64 = 0;
- ev.data.fd = fd;
- switch (rw) {
- case FDPOLL_MODE_READ:
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
- break;
- case FDPOLL_MODE_WRITE:
- ev.events = EPOLLOUT | EPOLLERR | EPOLLHUP;
- break;
- default:
- ev.events = 0;
+ ev.data.fd = fd;
+ ev.events = 0;
+
+ /* Set mode
+ */
+ if (mode_rw & poll_mode_read) {
+ ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
+ }
+
+ if (mode_rw & poll_mode_write) {
+ ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ }
+
+ if (unlikely (ev.events == 0)) {
SHOULDNT_HAPPEN;
return ret_error;
}
@@ -147,7 +151,7 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
static int
-_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
{
int fdidx;
uint32_t events;
@@ -181,14 +185,19 @@ _check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
*/
events = fdp->ep_events[fdidx].events;
- switch (rw) {
- case FDPOLL_MODE_READ:
- return events & (EPOLLIN | EPOLLERR | EPOLLHUP);
- case FDPOLL_MODE_WRITE:
- return events & (EPOLLOUT | EPOLLERR | EPOLLHUP);
- default:
- return -1;
+ if ((rw_mode & poll_mode_read) && (events & EPOLLIN)) {
+ return 1;
+ }
+
+ if ((rw_mode & poll_mode_write) && (events & EPOLLOUT)) {
+ return 1;
}
+
+ if (events & (EPOLLERR | EPOLLHUP)) {
+ return 1;
+ }
+
+ return -1;
}
@@ -207,30 +216,36 @@ _reset (cherokee_fdpoll_epoll_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
{
struct epoll_event ev;
ev.data.u64 = 0;
ev.data.fd = fd;
+ ev.events = 0;
- switch (rw) {
- case FDPOLL_MODE_READ:
- ev.events = EPOLLIN;
- break;
- case FDPOLL_MODE_WRITE:
- ev.events = EPOLLOUT;
- break;
- default:
- ev.events = 0;
+ /* Set mode
+ */
+ if (rw_mode & poll_mode_read) {
+ ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
+ }
+
+ if (rw_mode & poll_mode_write) {
+ ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ }
+
+ if (unlikely (ev.events == 0)) {
return ret_error;
}
- if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
+ /* Apply it
+ */
+ if (epoll_ctl (fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_EPOLL_CTL_MOD, fdp->ep_fd, fd);
return ret_error;
}
+
return ret_ok;
}

0 comments on commit d2e158e

Please sign in to comment.