Mercurial > dovecot > core-2.2
changeset 12578:7785af0ca36e
Added io_loop_move_io() and io_loop_move_timeout().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 13 Jan 2011 13:08:21 +0200 |
parents | a0ad3fbc3b0b |
children | e1f0f4798b5e |
files | src/lib/ioloop.c src/lib/ioloop.h |
diffstat | 2 files changed, 35 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/ioloop.c Thu Jan 13 13:08:02 2011 +0200 +++ b/src/lib/ioloop.c Thu Jan 13 13:08:21 2011 +0200 @@ -547,3 +547,32 @@ i_free(ioloop->default_log_prefix); ioloop->default_log_prefix = i_strdup(prefix); } + +struct io *io_loop_move_io(struct io **_io) +{ + struct io *new_io, *old_io = *_io; + struct io_file *old_io_file; + + i_assert((old_io->condition & IO_NOTIFY) == 0); + + if (old_io->ioloop == current_ioloop) + return old_io; + + old_io_file = (struct io_file *)old_io; + new_io = io_add(old_io_file->fd, old_io->condition, + old_io->callback, old_io->context); + io_remove(_io); + return new_io; +} + +struct timeout *io_loop_move_timeout(struct timeout **_timeout) +{ + struct timeout *new_to, *old_to = *_timeout; + + if (old_to->ioloop == current_ioloop) + return old_to; + + new_to = timeout_add(old_to->msecs, old_to->callback, old_to->context); + timeout_remove(_timeout); + return new_to; +}
--- a/src/lib/ioloop.h Thu Jan 13 13:08:02 2011 +0200 +++ b/src/lib/ioloop.h Thu Jan 13 13:08:21 2011 +0200 @@ -111,4 +111,10 @@ /* Set the default log prefix to use outside callbacks. */ void io_loop_set_default_log_prefix(struct ioloop *ioloop, const char *prefix); +/* Move the given I/O into the current I/O loop if it's not already + there. New I/O is returned, while the old one is freed. */ +struct io *io_loop_move_io(struct io **io); +/* Like io_loop_move_io(), but for timeouts. */ +struct timeout *io_loop_move_timeout(struct timeout **timeout); + #endif