dovecot-1.2: Don't break if io_remove() or timeout_remove() are ...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Nov 1 14:49:35 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/2c111b572eee
changeset: 8366:2c111b572eee
user: Timo Sirainen <tss at iki.fi>
date: Sat Nov 01 14:14:42 2008 +0200
description:
Don't break if io_remove() or timeout_remove() are called for non-active ioloops.
diffstat:
12 files changed, 71 insertions(+), 61 deletions(-)
src/lib/ioloop-epoll.c | 13 ++++------
src/lib/ioloop-internal.h | 11 +++++---
src/lib/ioloop-kqueue.c | 9 +++----
src/lib/ioloop-notify-dn.c | 8 +++---
src/lib/ioloop-notify-fd.c | 1
src/lib/ioloop-notify-inotify.c | 4 +--
src/lib/ioloop-notify-kqueue.c | 7 +++--
src/lib/ioloop-notify-none.c | 3 --
src/lib/ioloop-poll.c | 13 ++++------
src/lib/ioloop-select.c | 11 +++-----
src/lib/ioloop.c | 49 ++++++++++++++++++++++-----------------
src/lib/ioloop.h | 3 ++
diffs (truncated from 389 to 300 lines):
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-epoll.c
--- a/src/lib/ioloop-epoll.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-epoll.c Sat Nov 01 14:14:42 2008 +0200
@@ -83,9 +83,9 @@ static int epoll_event_mask(struct io_li
return events;
}
-void io_loop_handle_add(struct ioloop *ioloop, struct io_file *io)
-{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+void io_loop_handle_add(struct io_file *io)
+{
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
struct io_list **list;
struct epoll_event event;
int op;
@@ -118,10 +118,9 @@ void io_loop_handle_add(struct ioloop *i
}
}
-void io_loop_handle_remove(struct ioloop *ioloop, struct io_file *io,
- bool closed)
-{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+void io_loop_handle_remove(struct io_file *io, bool closed)
+{
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
struct io_list **list;
struct epoll_event event;
int op;
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-internal.h
--- a/src/lib/ioloop-internal.h Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-internal.h Sat Nov 01 14:14:42 2008 +0200
@@ -26,6 +26,8 @@ struct io {
io_callback_t *callback;
void *context;
+
+ struct ioloop *ioloop;
};
struct io_file {
@@ -46,6 +48,8 @@ struct timeout {
timeout_callback_t *callback;
void *context;
+
+ struct ioloop *ioloop;
};
int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r,
@@ -53,14 +57,13 @@ void io_loop_handle_timeouts(struct iolo
void io_loop_handle_timeouts(struct ioloop *ioloop);
/* I/O handler calls */
-void io_loop_handle_add(struct ioloop *ioloop, struct io_file *io);
-void io_loop_handle_remove(struct ioloop *ioloop, struct io_file *io,
- bool closed);
+void io_loop_handle_add(struct io_file *io);
+void io_loop_handle_remove(struct io_file *io, bool closed);
void io_loop_handler_init(struct ioloop *ioloop);
void io_loop_handler_deinit(struct ioloop *ioloop);
-void io_loop_notify_remove(struct ioloop *ioloop, struct io *io);
+void io_loop_notify_remove(struct io *io);
void io_loop_notify_handler_deinit(struct ioloop *ioloop);
#endif
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-kqueue.c
--- a/src/lib/ioloop-kqueue.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-kqueue.c Sat Nov 01 14:14:42 2008 +0200
@@ -56,9 +56,9 @@ void io_loop_handler_deinit(struct ioloo
i_free(ioloop->handler_context);
}
-void io_loop_handle_add(struct ioloop *ioloop, struct io_file *io)
+void io_loop_handle_add(struct io_file *io)
{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
struct kevent ev;
if ((io->io.condition & (IO_READ | IO_ERROR)) != 0) {
@@ -80,10 +80,9 @@ void io_loop_handle_add(struct ioloop *i
(void)array_append_space(&ctx->events);
}
-void io_loop_handle_remove(struct ioloop *ioloop, struct io_file *io,
- bool closed)
+void io_loop_handle_remove(struct io_file *io, bool closed)
{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
struct kevent ev;
if ((io->io.condition & (IO_READ | IO_ERROR)) != 0 && !closed) {
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-notify-dn.c
--- a/src/lib/ioloop-notify-dn.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-notify-dn.c Sat Nov 01 14:14:42 2008 +0200
@@ -148,10 +148,10 @@ enum io_notify_result io_add_notify(cons
return IO_NOTIFY_ADDED;
}
-void io_loop_notify_remove(struct ioloop *ioloop, struct io *_io)
-{
- struct ioloop_notify_handler_context *ctx =
- ioloop->notify_handler_context;
+void io_loop_notify_remove(struct io *_io)
+{
+ struct ioloop_notify_handler_context *ctx =
+ _io->ioloop->notify_handler_context;
struct io_notify *io = (struct io_notify *)_io;
if (fcntl(io->fd, F_NOTIFY, 0) < 0)
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-notify-fd.c
--- a/src/lib/ioloop-notify-fd.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-notify-fd.c Sat Nov 01 14:14:42 2008 +0200
@@ -15,6 +15,7 @@ struct io *io_notify_fd_add(struct ioloo
io->io.condition = IO_NOTIFY;
io->io.callback = callback;
io->io.context = context;
+ io->io.ioloop = current_ioloop;
io->fd = fd;
if (ctx->notifies != NULL) {
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-notify-inotify.c
--- a/src/lib/ioloop-notify-inotify.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-notify-inotify.c Sat Nov 01 14:14:42 2008 +0200
@@ -120,10 +120,10 @@ enum io_notify_result io_add_notify(cons
return IO_NOTIFY_ADDED;
}
-void io_loop_notify_remove(struct ioloop *ioloop, struct io *_io)
+void io_loop_notify_remove(struct io *_io)
{
struct ioloop_notify_handler_context *ctx =
- ioloop->notify_handler_context;
+ _io->ioloop->notify_handler_context;
struct io_notify *io = (struct io_notify *)_io;
if (io->fd != -1) {
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-notify-kqueue.c
--- a/src/lib/ioloop-notify-kqueue.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-notify-kqueue.c Sat Nov 01 14:14:42 2008 +0200
@@ -130,6 +130,7 @@ enum io_notify_result io_add_notify(cons
io->io.condition = IO_NOTIFY;
io->io.callback = callback;
io->io.context = context;
+ io->io.ioloop = current_ioloop;
io->refcount = 1;
io->fd = fd;
@@ -147,16 +148,16 @@ enum io_notify_result io_add_notify(cons
if (ctx->event_io == NULL) {
ctx->event_io = io_add(ctx->kq, IO_READ, event_callback,
- current_ioloop->notify_handler_context);
+ io->io.ioloop->notify_handler_context);
}
*io_r = &io->io;
return IO_NOTIFY_ADDED;
}
-void io_loop_notify_remove(struct ioloop *ioloop, struct io *_io)
+void io_loop_notify_remove(struct io *_io)
{
struct ioloop_notify_handler_context *ctx =
- ioloop->notify_handler_context;
+ _io->ioloop->notify_handler_context;
struct io_notify *io = (struct io_notify *)_io;
struct kevent ev;
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-notify-none.c
--- a/src/lib/ioloop-notify-none.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-notify-none.c Sat Nov 01 14:14:42 2008 +0200
@@ -15,8 +15,7 @@ io_add_notify(const char *path ATTR_UNUS
return IO_NOTIFY_NOSUPPORT;
}
-void io_loop_notify_remove(struct ioloop *ioloop ATTR_UNUSED,
- struct io *io ATTR_UNUSED)
+void io_loop_notify_remove(struct io *io ATTR_UNUSED)
{
}
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-poll.c
--- a/src/lib/ioloop-poll.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-poll.c Sat Nov 01 14:14:42 2008 +0200
@@ -42,9 +42,9 @@ void io_loop_handler_deinit(struct ioloo
#define IO_POLL_INPUT (POLLIN | POLLPRI | IO_POLL_ERROR)
#define IO_POLL_OUTPUT (POLLOUT | IO_POLL_ERROR)
-void io_loop_handle_add(struct ioloop *ioloop, struct io_file *io)
-{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+void io_loop_handle_add(struct io_file *io)
+{
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
enum io_condition condition = io->io.condition;
unsigned int old_count;
int index, fd = io->fd;
@@ -94,10 +94,9 @@ void io_loop_handle_add(struct ioloop *i
ctx->fds[index].events |= IO_POLL_ERROR;
}
-void io_loop_handle_remove(struct ioloop *ioloop, struct io_file *io,
- bool closed ATTR_UNUSED)
-{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+void io_loop_handle_remove(struct io_file *io, bool closed ATTR_UNUSED)
+{
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
enum io_condition condition = io->io.condition;
int index, fd = io->fd;
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop-select.c
--- a/src/lib/ioloop-select.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop-select.c Sat Nov 01 14:14:42 2008 +0200
@@ -53,9 +53,9 @@ void io_loop_handler_deinit(struct ioloo
i_free(ioloop->handler_context);
}
-void io_loop_handle_add(struct ioloop *ioloop, struct io_file *io)
+void io_loop_handle_add(struct io_file *io)
{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
enum io_condition condition = io->io.condition;
int fd = io->fd;
@@ -74,10 +74,9 @@ void io_loop_handle_add(struct ioloop *i
ctx->highest_fd = io->fd;
}
-void io_loop_handle_remove(struct ioloop *ioloop, struct io_file *io,
- bool closed ATTR_UNUSED)
+void io_loop_handle_remove(struct io_file *io, bool closed ATTR_UNUSED)
{
- struct ioloop_handler_context *ctx = ioloop->handler_context;
+ struct ioloop_handler_context *ctx = io->io.ioloop->handler_context;
enum io_condition condition = io->io.condition;
int fd = io->fd;
@@ -93,7 +92,7 @@ void io_loop_handle_remove(struct ioloop
/* check if we removed the highest fd */
if (io->fd == ctx->highest_fd)
- update_highest_fd(ioloop);
+ update_highest_fd(io->io.ioloop);
}
i_free(io);
}
diff -r f97099eb4dee -r 2c111b572eee src/lib/ioloop.c
--- a/src/lib/ioloop.c Fri Oct 24 16:06:07 2008 +0200
+++ b/src/lib/ioloop.c Sat Nov 01 14:14:42 2008 +0200
@@ -33,18 +33,19 @@ struct io *io_add(int fd, enum io_condit
io->io.condition = condition;
io->io.callback = callback;
io->io.context = context;
+ io->io.ioloop = current_ioloop;
io->refcount = 1;
io->fd = fd;
- if (current_ioloop->handler_context == NULL)
- io_loop_handler_init(current_ioloop);
- io_loop_handle_add(current_ioloop, io);
-
- if (current_ioloop->io_files != NULL) {
- current_ioloop->io_files->prev = io;
- io->next = current_ioloop->io_files;
- }
- current_ioloop->io_files = io;
+ if (io->io.ioloop->handler_context == NULL)
+ io_loop_handler_init(io->io.ioloop);
+ io_loop_handle_add(io);
+
+ if (io->io.ioloop->io_files != NULL) {
+ io->io.ioloop->io_files->prev = io;
+ io->next = io->io.ioloop->io_files;
+ }
+ io->io.ioloop->io_files = io;
return &io->io;
}
@@ -53,15 +54,15 @@ static void io_file_unlink(struct io_fil
if (io->prev != NULL)
io->prev->next = io->next;
else
- current_ioloop->io_files = io->next;
+ io->io.ioloop->io_files = io->next;
if (io->next != NULL)
io->next->prev = io->prev;
/* if we got here from an I/O handler callback, make sure we
don't try to handle this one next. */
- if (current_ioloop->next_io_file == io)
- current_ioloop->next_io_file = io->next;
+ if (io->io.ioloop->next_io_file == io)
More information about the dovecot-cvs
mailing list