ioloop-poll.c revision cd65920767c81e079994df625ade27531f72f5c2
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* @UNSAFE: whole file */
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "lib.h"
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen#include "ioloop-internal.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen#ifdef IOLOOP_POLL
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include <fcntl.h>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include <sys/poll.h>
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct ioloop_handler_context {
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen unsigned int fds_count, fds_pos;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct pollfd *fds;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int idx_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int *fd_index;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen};
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainenvoid io_loop_handler_init(struct ioloop *ioloop, unsigned int initial_fd_count)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen{
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen struct ioloop_handler_context *ctx;
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen ioloop->handler_context = ctx = i_new(struct ioloop_handler_context, 1);
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen ctx->fds_count = initial_fd_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->fds = i_new(struct pollfd, ctx->fds_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->idx_count = initial_fd_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->fd_index = i_new(int, ctx->idx_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen memset(ctx->fd_index, 0xff, sizeof(int) * ctx->idx_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid io_loop_handler_deinit(struct ioloop *ioloop)
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen{
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen i_free(ioloop->handler_context->fds);
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen i_free(ioloop->handler_context->fd_index);
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen i_free(ioloop->handler_context);
26a8b7deb3a5b6f26f9c4d71538e1248f680e4beTimo Sirainen}
26a8b7deb3a5b6f26f9c4d71538e1248f680e4beTimo Sirainen
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen#define IO_POLL_ERROR (POLLERR | POLLHUP | POLLNVAL)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define IO_POLL_INPUT (POLLIN | POLLPRI | IO_POLL_ERROR)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define IO_POLL_OUTPUT (POLLOUT | IO_POLL_ERROR)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid io_loop_handle_add(struct io_file *io)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen{
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen enum io_condition condition = io->io.condition;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int old_count;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen int index, old_events, fd = io->fd;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((unsigned int)fd >= ctx->idx_count) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* grow the fd -> index array */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen old_count = ctx->idx_count;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->idx_count = nearest_power((unsigned int) fd+1);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen ctx->fd_index = i_realloc(ctx->fd_index,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen sizeof(int) * old_count,
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainen sizeof(int) * ctx->idx_count);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen memset(ctx->fd_index + old_count, 0xff,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen sizeof(int) * (ctx->idx_count-old_count));
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen }
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainen if (ctx->fds_pos >= ctx->fds_count) {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* grow the fd array */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen old_count = ctx->fds_count;
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen ctx->fds_count = nearest_power(ctx->fds_count+1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->fds = i_realloc(ctx->fds,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sizeof(struct pollfd) * old_count,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sizeof(struct pollfd) * ctx->fds_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen if (ctx->fd_index[fd] != -1) {
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen /* update existing pollfd */
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen index = ctx->fd_index[fd];
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen } else {
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen /* add new pollfd */
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen index = ctx->fds_pos++;
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen ctx->fd_index[fd] = index;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen ctx->fds[index].fd = fd;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen ctx->fds[index].events = 0;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen ctx->fds[index].revents = 0;
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen }
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen old_events = ctx->fds[index].events;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen if (condition & IO_READ)
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen ctx->fds[index].events |= IO_POLL_INPUT;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen if (condition & IO_WRITE)
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen ctx->fds[index].events |= IO_POLL_OUTPUT;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen if (condition & IO_ERROR)
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen ctx->fds[index].events |= IO_POLL_ERROR;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen i_assert(ctx->fds[index].events != old_events);
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen}
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainenvoid io_loop_handle_remove(struct io_file *io, bool closed ATTR_UNUSED)
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen{
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen enum io_condition condition = io->io.condition;
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int index, fd = io->fd;
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen index = ctx->fd_index[fd];
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_assert(index >= 0 && (unsigned int) index < ctx->fds_count);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen#ifdef DEBUG
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (!closed) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* io_remove() is required to be called before fd is closed.
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen This is required by epoll/kqueue, but since poll is more
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen commonly used while developing, this check here should catch
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen the error early enough not to cause problems for kqueue
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen users. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (fcntl(io->fd, F_GETFD, 0) < 0) {
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen if (errno == EBADF)
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen i_panic("io_remove(%d) called too late", io->fd);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen else
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen i_error("fcntl(%d, F_GETFD) failed: %m", io->fd);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen }
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen }
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen#endif
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen i_free(io);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (condition & IO_READ) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen ctx->fds[index].events &= ~(POLLIN|POLLPRI);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen ctx->fds[index].revents &= ~(POLLIN|POLLPRI);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen }
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen if (condition & IO_WRITE) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen ctx->fds[index].events &= ~POLLOUT;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ctx->fds[index].revents &= ~POLLOUT;
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen }
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen if ((ctx->fds[index].events & (POLLIN|POLLOUT)) == 0) {
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* remove the whole pollfd */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen ctx->fd_index[ctx->fds[index].fd] = -1;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (--ctx->fds_pos == (unsigned int) index)
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen return; /* removing last one */
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* move the last pollfd over the removed one */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen ctx->fds[index] = ctx->fds[ctx->fds_pos];
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen ctx->fd_index[ctx->fds[index].fd] = index;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen }
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen}
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainenvoid io_loop_handler_run(struct ioloop *ioloop)
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen{
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen struct ioloop_handler_context *ctx = ioloop->handler_context;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen struct pollfd *pollfd;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen struct timeval tv;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen struct io_file *io;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen unsigned int t_id;
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int msecs, ret;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen bool call;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* get the time left for next timeout task */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen msecs = io_loop_get_wait_time(ioloop, &tv);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen#ifdef _AIX
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen if (msecs > 1000) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* AIX seems to check IO_POLL_ERRORs only at the beginning of
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen the poll() call, not during it. keep timeouts short enough
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen so that we'll notice them pretty quickly. */
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen msecs = 1000;
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen }
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen#endif
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen ret = poll(ctx->fds, ctx->fds_pos, msecs);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (ret < 0 && errno != EINTR)
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen i_fatal("poll(): %m");
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* execute timeout handlers */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen io_loop_handle_timeouts(ioloop);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (ret <= 0 || !ioloop->running) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* no I/O events */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen return;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen }
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen io = ioloop->io_files;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen for (; io != NULL && ret > 0; io = ioloop->next_io_file) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen ioloop->next_io_file = io->next;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen pollfd = &ctx->fds[ctx->fd_index[io->fd]];
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen if (pollfd->revents != 0) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (pollfd->revents & POLLNVAL) {
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen i_error("invalid I/O fd %d, callback %p",
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen io->fd, (void *) io->io.callback);
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen pollfd->events = 0;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen pollfd->revents = 0;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen call = TRUE;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen } else if ((io->io.condition &
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) {
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen call = TRUE;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen pollfd->revents = 0;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen } else if (io->io.condition & IO_READ) {
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen call = (pollfd->revents & IO_POLL_INPUT) != 0;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen pollfd->revents &= ~IO_POLL_INPUT;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen } else if (io->io.condition & IO_WRITE) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen call = (pollfd->revents & IO_POLL_OUTPUT) != 0;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen pollfd->revents &= ~IO_POLL_OUTPUT;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen } else if (io->io.condition & IO_ERROR) {
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen call = (pollfd->revents & IO_POLL_ERROR) != 0;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen pollfd->revents &= ~IO_POLL_ERROR;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen } else {
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen call = FALSE;
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen }
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen if (pollfd->revents == 0)
003079baf8056c81c25162a176a89f9169cc374fTimo Sirainen ret--;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (call) {
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen t_id = t_push();
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen io->io.callback(io->io.context);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (t_pop() != t_id) {
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen i_panic("Leaked a t_pop() call in "
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen "I/O handler %p",
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen (void *)io->io.callback);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen }
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen }
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen }
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen }
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen}
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen#endif
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen