diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
commit | 0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch) | |
tree | 3f3789daa2f6db22da6e55e92bee0062a7d613fe /src/lib/ioloop-iolist.c | |
parent | Initial commit. (diff) | |
download | dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip |
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/ioloop-iolist.c')
-rw-r--r-- | src/lib/ioloop-iolist.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/ioloop-iolist.c b/src/lib/ioloop-iolist.c new file mode 100644 index 0000000..28229af --- /dev/null +++ b/src/lib/ioloop-iolist.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru> + * + * This software is released under the MIT license. + */ + +#include "lib.h" +#include "ioloop-private.h" +#include "ioloop-iolist.h" + +bool ioloop_iolist_add(struct io_list *list, struct io_file *io) +{ + int i, idx; + + if ((io->io.condition & IO_READ) != 0) + idx = IOLOOP_IOLIST_INPUT; + else if ((io->io.condition & IO_WRITE) != 0) + idx = IOLOOP_IOLIST_OUTPUT; + else if ((io->io.condition & IO_ERROR) != 0) + idx = IOLOOP_IOLIST_ERROR; + else { + i_unreached(); + } + + if (list->ios[idx] != NULL) { + i_panic("io_add(0x%x) called twice fd=%d, callback=%p -> %p", + io->io.condition, io->fd, list->ios[idx]->io.callback, + io->io.callback); + } + i_assert(list->ios[idx] == NULL); + list->ios[idx] = io; + + /* check if this was the first one */ + for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) { + if (i != idx && list->ios[i] != NULL) + return FALSE; + } + + return TRUE; +} + +bool ioloop_iolist_del(struct io_list *list, struct io_file *io) +{ + bool last = TRUE; + int i; + + for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) { + if (list->ios[i] != NULL) { + if (list->ios[i] == io) + list->ios[i] = NULL; + else + last = FALSE; + } + } + return last; +} |