Andrey Panin
2004-Oct-25 12:33 UTC
[Dovecot] [PATCH] move iolist functions into separate file
Hello, attached patch extracts iolist related functions into separate file and makes it a little more generic. This functions will be used by the new ioloop handler based on the BSD kqueue API. Please consider applying. Best regards. -- Andrey Panin | Linux and UNIX system administrator pazke at donpac.ru | PGP key: wwwkeys.pgp.net -------------- next part -------------- diff -udrpNX /usr/share/dontdiff -x debian dovecot-1.0-test51.vanilla/src/lib/iolist.c dovecot-1.0-test51/src/lib/iolist.c --- dovecot-1.0-test51.vanilla/src/lib/iolist.c 1970-01-01 03:00:00.000000000 +0300 +++ dovecot-1.0-test51/src/lib/iolist.c 2004-10-24 16:36:45.000000000 +0400 @@ -0,0 +1,56 @@ + +#include "lib.h" +#include "iolist.h" +#include "ioloop-internal.h" + +int iolist_add(struct io_list *list, struct io *io) +{ + if ((io->condition & IO_READ) != 0) { + i_assert(list->ios[IOLIST_INPUT] == NULL); + list->ios[IOLIST_INPUT] = io; + return list->ios[IOLIST_OUTPUT] == NULL; + } + if ((io->condition & IO_WRITE) != 0) { + i_assert(list->ios[IOLIST_OUTPUT] == NULL); + list->ios[IOLIST_OUTPUT] = io; + return list->ios[IOLIST_INPUT] == NULL; + } + + i_unreached(); + return TRUE; +} + +int iolist_del(struct io_list *list, struct io *io) +{ + if (list->ios[IOLIST_INPUT] == io) { + list->ios[IOLIST_INPUT] = NULL; + return list->ios[IOLIST_OUTPUT] == NULL; + } + if (list->ios[IOLIST_OUTPUT] == io) { + list->ios[IOLIST_OUTPUT] = NULL; + return list->ios[IOLIST_INPUT] == NULL; + } + + i_unreached(); + return TRUE; +} + +int iolist_events(struct io_list *list, int rmask, int wmask) +{ + int events = 0, i; + struct io *io; + + for (i = 0; i < IOLIST_IOS_PER_FD; i++) { + io = list->ios[i]; + + if (io == NULL) + continue; + + if (io->condition & IO_READ) + events |= rmask; + if (io->condition & IO_WRITE) + events |= wmask; + } + + return events; +} diff -udrpNX /usr/share/dontdiff -x debian dovecot-1.0-test51.vanilla/src/lib/iolist.h dovecot-1.0-test51/src/lib/iolist.h --- dovecot-1.0-test51.vanilla/src/lib/iolist.h 1970-01-01 03:00:00.000000000 +0300 +++ dovecot-1.0-test51/src/lib/iolist.h 2004-10-24 16:36:57.000000000 +0400 @@ -0,0 +1,19 @@ +#ifndef __IOLIST_H +#define __IOLIST_H + +enum { + IOLIST_INPUT, + IOLIST_OUTPUT, + + IOLIST_IOS_PER_FD +}; + +struct io_list { + struct io *ios[IOLIST_IOS_PER_FD]; +}; + +int iolist_add(struct io_list *list, struct io *io); +int iolist_del(struct io_list *list, struct io *io); +int iolist_events(struct io_list *list, int rmask, int wmask); + +#endif /* __IOLIST_H */ diff -udrpNX /usr/share/dontdiff -x debian dovecot-1.0-test51.vanilla/src/lib/ioloop-epoll.c dovecot-1.0-test51/src/lib/ioloop-epoll.c --- dovecot-1.0-test51.vanilla/src/lib/ioloop-epoll.c 2004-10-07 23:37:44.000000000 +0400 +++ dovecot-1.0-test51/src/lib/ioloop-epoll.c 2004-10-24 16:42:09.000000000 +0400 @@ -12,6 +12,7 @@ /* @UNSAFE: whole file */ #include "lib.h" +#include "iolist.h" #include "ioloop-internal.h" #ifdef IOLOOP_EPOLL @@ -21,13 +22,6 @@ #define INITIAL_EPOLL_EVENTS 128 -enum { - EPOLL_LIST_INPUT, - EPOLL_LIST_OUTPUT, - - EPOLL_IOS_PER_FD -}; - struct ioloop_handler_data { int epfd; int events_size, events_pos; @@ -37,10 +31,6 @@ struct ioloop_handler_data { struct io_list **fd_index; }; -struct io_list { - struct io *ios[EPOLL_IOS_PER_FD]; -}; - void io_loop_handler_init(struct ioloop *ioloop) { struct ioloop_handler_data *data; @@ -74,58 +64,6 @@ void io_loop_handler_deinit(struct ioloo #define IO_EPOLL_INPUT (EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP) #define IO_EPOLL_OUTPUT (EPOLLOUT | EPOLLERR | EPOLLHUP) -static int epoll_event_mask(struct io_list *list) -{ - int events = 0, i; - struct io *io; - - for (i = 0; i < EPOLL_IOS_PER_FD; i++) { - io = list->ios[i]; - - if (io == NULL) - continue; - - if (io->condition & IO_READ) - events |= IO_EPOLL_INPUT; - if (io->condition & IO_WRITE) - events |= IO_EPOLL_OUTPUT; - } - - return events; -} - -static int iolist_add(struct io_list *list, struct io *io) -{ - if ((io->condition & IO_READ) != 0) { - i_assert(list->ios[EPOLL_LIST_INPUT] == NULL); - list->ios[EPOLL_LIST_INPUT] = io; - return list->ios[EPOLL_LIST_OUTPUT] == NULL; - } - if ((io->condition & IO_WRITE) != 0) { - i_assert(list->ios[EPOLL_LIST_OUTPUT] == NULL); - list->ios[EPOLL_LIST_OUTPUT] = io; - return list->ios[EPOLL_LIST_INPUT] == NULL; - } - - i_unreached(); - return TRUE; -} - -static int iolist_del(struct io_list *list, struct io *io) -{ - if (list->ios[EPOLL_LIST_INPUT] == io) { - list->ios[EPOLL_LIST_INPUT] = NULL; - return list->ios[EPOLL_LIST_OUTPUT] == NULL; - } - if (list->ios[EPOLL_LIST_OUTPUT] == io) { - list->ios[EPOLL_LIST_OUTPUT] = NULL; - return list->ios[EPOLL_LIST_INPUT] == NULL; - } - - i_unreached(); - return TRUE; -} - void io_loop_handle_add(struct ioloop *ioloop, struct io *io) { struct ioloop_handler_data *data = ioloop->handler_data; @@ -155,7 +93,7 @@ void io_loop_handle_add(struct ioloop *i first = iolist_add(list, io); event.data.ptr = list; - event.events = epoll_event_mask(list); + event.events = iolist_events(list, IO_EPOLL_INPUT, IO_EPOLL_OUTPUT); op = first ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; @@ -184,7 +122,7 @@ void io_loop_handle_remove(struct ioloop last = iolist_del(list, io); event.data.ptr = list; - event.events = epoll_event_mask(list); + event.events = iolist_events(list, IO_EPOLL_INPUT, IO_EPOLL_OUTPUT); op = last ? EPOLL_CTL_DEL : EPOLL_CTL_MOD; @@ -224,7 +162,7 @@ void io_loop_handler_run(struct ioloop * while (ret-- > 0) { list = event->data.ptr; - for (i = 0; i < EPOLL_IOS_PER_FD; i++) { + for (i = 0; i < IOLIST_IOS_PER_FD; i++) { io = list->ios[i]; if (io == NULL) continue; diff -udrpNX /usr/share/dontdiff -x debian dovecot-1.0-test51.vanilla/src/lib/Makefile.am dovecot-1.0-test51/src/lib/Makefile.am --- dovecot-1.0-test51.vanilla/src/lib/Makefile.am 2004-10-05 19:28:42.000000000 +0400 +++ dovecot-1.0-test51/src/lib/Makefile.am 2004-10-24 16:35:44.000000000 +0400 @@ -31,6 +31,7 @@ liblib_a_SOURCES = \ ioloop-poll.c \ ioloop-select.c \ ioloop-epoll.c \ + iolist.c \ lib.c \ lib-signals.c \ md4.c \ @@ -93,6 +94,7 @@ noinst_HEADERS = \ istream-internal.h \ ioloop.h \ ioloop-internal.h \ + iolist.h \ lib.h \ lib-signals.h \ macros.h \ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <http://dovecot.org/pipermail/dovecot/attachments/20041025/5638bbe4/attachment-0001.bin>
Reasonably Related Threads
- [PATCH] [RFC] epoll based ioloop handler (now with patch)
- [PATCH] Request for testing: BSD kqueue ioloop handler
- Panic: file ioloop-iolist.c: line 25 (ioloop_iolist_add):assertion failed
- Panic: file ioloop-iolist.c: line 25 (ioloop_iolist_add): assertion failed
- RC11 Build Failure on FreeBSD 6.1