From e54e9176a34065552d222be2bd63935d35232635 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 9 Apr 2007 09:23:31 +0200 Subject: [PATCH] [MINOR] ev_* : moved the poll function closer to fd_* --- src/ev_epoll.c | 164 ++++++++++++++++++++++++------------------------ src/ev_poll.c | 106 +++++++++++++++---------------- src/ev_select.c | 114 +++++++++++++++++---------------- 3 files changed, 189 insertions(+), 195 deletions(-) diff --git a/src/ev_epoll.c b/src/ev_epoll.c index 56049bc04..fe0e1a29e 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -96,89 +96,6 @@ REGPRM1 static void __fd_clo(const int fd) 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 */ @@ -296,6 +213,87 @@ REGPRM2 static void epoll_poll(struct poller *p, int wait_time) } } +/* + * 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. */ diff --git a/src/ev_poll.c b/src/ev_poll.c index 542742a0c..b2010cb28 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -78,60 +78,6 @@ REGPRM1 static void __fd_rem(const int fd) 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 */ @@ -206,6 +152,58 @@ REGPRM2 static void poll_poll(struct poller *p, int wait_time) } +/* + * 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; +} + /* * The only exported function. Returns 1. */ diff --git a/src/ev_select.c b/src/ev_select.c index d019c2147..7340d3042 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -76,64 +76,6 @@ REGPRM1 static void __fd_rem(int fd) 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 */ @@ -207,6 +149,62 @@ REGPRM2 static void select_poll(struct poller *p, int wait_time) } } +/* + * 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. */