[MINOR] ev_* : moved the poll function closer to fd_*
diff --git a/src/ev_epoll.c b/src/ev_epoll.c
index 56049bc..fe0e1a2 100644
--- a/src/ev_epoll.c
+++ b/src/ev_epoll.c
@@ -96,89 +96,6 @@
FD_CLR(fd, old_evts[DIR_WR]);
}
-
-
-/*
- * Initialization of the epoll() poller.
- * Returns 0 in case of failure, non-zero in case of success. If it fails, it
- * disables the poller by setting its pref to 0.
- */
-REGPRM1 static int epoll_init(struct poller *p)
-{
- __label__ fail_pwevt, fail_prevt, fail_swevt, fail_srevt, fail_ee, fail_fd;
- int fd_set_bytes;
-
- p->private = NULL;
- fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
-
- epoll_fd = epoll_create(global.maxsock + 1);
- if (epoll_fd < 0)
- goto fail_fd;
-
- epoll_events = (struct epoll_event*)
- calloc(1, sizeof(struct epoll_event) * global.maxsock);
-
- if (epoll_events == NULL)
- goto fail_ee;
-
- if ((old_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_prevt;
-
- if ((old_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_pwevt;
-
- if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_srevt;
-
- if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_swevt;
-
- return 1;
-
- fail_swevt:
- free(fd_evts[DIR_RD]);
- fail_srevt:
- free(old_evts[DIR_WR]);
- fail_pwevt:
- free(old_evts[DIR_RD]);
- fail_prevt:
- free(epoll_events);
- fail_ee:
- close(epoll_fd);
- epoll_fd = 0;
- fail_fd:
- p->pref = 0;
- return 0;
-}
-
-/*
- * Termination of the epoll() poller.
- * Memory is released and the poller is marked as unselectable.
- */
-REGPRM1 static void epoll_term(struct poller *p)
-{
- if (fd_evts[DIR_WR])
- free(fd_evts[DIR_WR]);
-
- if (fd_evts[DIR_RD])
- free(fd_evts[DIR_RD]);
-
- if (old_evts[DIR_WR])
- free(old_evts[DIR_WR]);
-
- if (old_evts[DIR_RD])
- free(old_evts[DIR_RD]);
-
- if (epoll_events)
- free(epoll_events);
-
- close(epoll_fd);
- epoll_fd = 0;
-
- p->private = NULL;
- p->pref = 0;
-}
-
/*
* epoll() poller
*/
@@ -297,6 +214,87 @@
}
/*
+ * Initialization of the epoll() poller.
+ * Returns 0 in case of failure, non-zero in case of success. If it fails, it
+ * disables the poller by setting its pref to 0.
+ */
+REGPRM1 static int epoll_init(struct poller *p)
+{
+ __label__ fail_pwevt, fail_prevt, fail_swevt, fail_srevt, fail_ee, fail_fd;
+ int fd_set_bytes;
+
+ p->private = NULL;
+ fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
+
+ epoll_fd = epoll_create(global.maxsock + 1);
+ if (epoll_fd < 0)
+ goto fail_fd;
+
+ epoll_events = (struct epoll_event*)
+ calloc(1, sizeof(struct epoll_event) * global.maxsock);
+
+ if (epoll_events == NULL)
+ goto fail_ee;
+
+ if ((old_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_prevt;
+
+ if ((old_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_pwevt;
+
+ if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_srevt;
+
+ if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_swevt;
+
+ return 1;
+
+ fail_swevt:
+ free(fd_evts[DIR_RD]);
+ fail_srevt:
+ free(old_evts[DIR_WR]);
+ fail_pwevt:
+ free(old_evts[DIR_RD]);
+ fail_prevt:
+ free(epoll_events);
+ fail_ee:
+ close(epoll_fd);
+ epoll_fd = 0;
+ fail_fd:
+ p->pref = 0;
+ return 0;
+}
+
+/*
+ * Termination of the epoll() poller.
+ * Memory is released and the poller is marked as unselectable.
+ */
+REGPRM1 static void epoll_term(struct poller *p)
+{
+ if (fd_evts[DIR_WR])
+ free(fd_evts[DIR_WR]);
+
+ if (fd_evts[DIR_RD])
+ free(fd_evts[DIR_RD]);
+
+ if (old_evts[DIR_WR])
+ free(old_evts[DIR_WR]);
+
+ if (old_evts[DIR_RD])
+ free(old_evts[DIR_RD]);
+
+ if (epoll_events)
+ free(epoll_events);
+
+ close(epoll_fd);
+ epoll_fd = 0;
+
+ p->private = NULL;
+ p->pref = 0;
+}
+
+/*
* The only exported function. Returns 1.
*/
int epoll_register(struct poller *p)
diff --git a/src/ev_poll.c b/src/ev_poll.c
index 542742a..b2010cb 100644
--- a/src/ev_poll.c
+++ b/src/ev_poll.c
@@ -78,60 +78,6 @@
FD_CLR(fd, fd_evts[DIR_WR]);
}
-
-
-/*
- * Initialization of the poll() poller.
- * Returns 0 in case of failure, non-zero in case of success. If it fails, it
- * disables the poller by setting its pref to 0.
- */
-REGPRM1 static int poll_init(struct poller *p)
-{
- __label__ fail_swevt, fail_srevt, fail_pe;
- int fd_set_bytes;
-
- p->private = NULL;
- fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
-
- poll_events = (struct pollfd*)
- calloc(1, sizeof(struct pollfd) * global.maxsock);
-
- if (poll_events == NULL)
- goto fail_pe;
-
- if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_srevt;
-
- if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_swevt;
-
- return 1;
-
- fail_swevt:
- free(fd_evts[DIR_RD]);
- fail_srevt:
- free(poll_events);
- fail_pe:
- p->pref = 0;
- return 0;
-}
-
-/*
- * Termination of the poll() poller.
- * Memory is released and the poller is marked as unselectable.
- */
-REGPRM1 static void poll_term(struct poller *p)
-{
- if (fd_evts[DIR_WR])
- free(fd_evts[DIR_WR]);
- if (fd_evts[DIR_RD])
- free(fd_evts[DIR_RD]);
- if (poll_events)
- free(poll_events);
- p->private = NULL;
- p->pref = 0;
-}
-
/*
* Poll() poller
*/
@@ -204,6 +150,58 @@
}
}
+}
+
+/*
+ * Initialization of the poll() poller.
+ * Returns 0 in case of failure, non-zero in case of success. If it fails, it
+ * disables the poller by setting its pref to 0.
+ */
+REGPRM1 static int poll_init(struct poller *p)
+{
+ __label__ fail_swevt, fail_srevt, fail_pe;
+ int fd_set_bytes;
+
+ p->private = NULL;
+ fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
+
+ poll_events = (struct pollfd*)
+ calloc(1, sizeof(struct pollfd) * global.maxsock);
+
+ if (poll_events == NULL)
+ goto fail_pe;
+
+ if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_srevt;
+
+ if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_swevt;
+
+ return 1;
+
+ fail_swevt:
+ free(fd_evts[DIR_RD]);
+ fail_srevt:
+ free(poll_events);
+ fail_pe:
+ p->pref = 0;
+ return 0;
+}
+
+/*
+ * Termination of the poll() poller.
+ * Memory is released and the poller is marked as unselectable.
+ */
+REGPRM1 static void poll_term(struct poller *p)
+{
+ if (fd_evts[DIR_WR])
+ free(fd_evts[DIR_WR]);
+ if (fd_evts[DIR_RD])
+ free(fd_evts[DIR_RD]);
+ if (poll_events)
+ free(poll_events);
+ p->private = NULL;
+ p->pref = 0;
}
/*
diff --git a/src/ev_select.c b/src/ev_select.c
index d019c21..7340d30 100644
--- a/src/ev_select.c
+++ b/src/ev_select.c
@@ -76,64 +76,6 @@
FD_CLR(fd, fd_evts[DIR_WR]);
}
-
-
-/*
- * Initialization of the select() poller.
- * Returns 0 in case of failure, non-zero in case of success. If it fails, it
- * disables the poller by setting its pref to 0.
- */
-REGPRM1 static int select_init(struct poller *p)
-{
- __label__ fail_swevt, fail_srevt, fail_wevt, fail_revt;
- int fd_set_bytes;
-
- p->private = NULL;
- fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
-
- if ((tmp_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_revt;
-
- if ((tmp_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_wevt;
-
- if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_srevt;
-
- if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
- goto fail_swevt;
-
- return 1;
-
- fail_swevt:
- free(fd_evts[DIR_RD]);
- fail_srevt:
- free(tmp_evts[DIR_WR]);
- fail_wevt:
- free(tmp_evts[DIR_RD]);
- fail_revt:
- p->pref = 0;
- return 0;
-}
-
-/*
- * Termination of the select() poller.
- * Memory is released and the poller is marked as unselectable.
- */
-REGPRM1 static void select_term(struct poller *p)
-{
- if (fd_evts[DIR_WR])
- free(fd_evts[DIR_WR]);
- if (fd_evts[DIR_RD])
- free(fd_evts[DIR_RD]);
- if (tmp_evts[DIR_WR])
- free(tmp_evts[DIR_WR]);
- if (tmp_evts[DIR_RD])
- free(tmp_evts[DIR_RD]);
- p->private = NULL;
- p->pref = 0;
-}
-
/*
* Select() poller
*/
@@ -208,6 +150,62 @@
}
/*
+ * Initialization of the select() poller.
+ * Returns 0 in case of failure, non-zero in case of success. If it fails, it
+ * disables the poller by setting its pref to 0.
+ */
+REGPRM1 static int select_init(struct poller *p)
+{
+ __label__ fail_swevt, fail_srevt, fail_wevt, fail_revt;
+ int fd_set_bytes;
+
+ p->private = NULL;
+ fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
+
+ if ((tmp_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_revt;
+
+ if ((tmp_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_wevt;
+
+ if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_srevt;
+
+ if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+ goto fail_swevt;
+
+ return 1;
+
+ fail_swevt:
+ free(fd_evts[DIR_RD]);
+ fail_srevt:
+ free(tmp_evts[DIR_WR]);
+ fail_wevt:
+ free(tmp_evts[DIR_RD]);
+ fail_revt:
+ p->pref = 0;
+ return 0;
+}
+
+/*
+ * Termination of the select() poller.
+ * Memory is released and the poller is marked as unselectable.
+ */
+REGPRM1 static void select_term(struct poller *p)
+{
+ if (fd_evts[DIR_WR])
+ free(fd_evts[DIR_WR]);
+ if (fd_evts[DIR_RD])
+ free(fd_evts[DIR_RD]);
+ if (tmp_evts[DIR_WR])
+ free(tmp_evts[DIR_WR]);
+ if (tmp_evts[DIR_RD])
+ free(tmp_evts[DIR_RD]);
+ p->private = NULL;
+ p->pref = 0;
+}
+
+/*
* The only exported function. Returns 1.
*/
int select_register(struct poller *p)