]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added io_loop_move_io() and io_loop_move_timeout().
authorTimo Sirainen <tss@iki.fi>
Thu, 13 Jan 2011 11:08:21 +0000 (13:08 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 13 Jan 2011 11:08:21 +0000 (13:08 +0200)
src/lib/ioloop.c
src/lib/ioloop.h

index 1251cc5b9c3008f68c6eeeffc87e9d7d4239ee01..5d393a3d5e40086b4c1458458bd92c58c2cac9fb 100644 (file)
@@ -547,3 +547,32 @@ void io_loop_set_default_log_prefix(struct ioloop *ioloop, const char *prefix)
        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;
+}
index 41ff6f76af9b0182006dde9e26b0e8bfc4a4dcb9..66c65bc2ed8fc94128467e5e10037dd964d5fe90 100644 (file)
@@ -111,4 +111,10 @@ void io_loop_log_set_prefix(struct ioloop_log *log, const char *prefix);
 /* 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