[dovecot-cvs]
dovecot/src/lib ioloop-epoll.c, 1.6, 1.7 ioloop-poll.c,
1.27, 1.28 ioloop-select.c, 1.21, 1.22 ioloop.h, 1.12, 1.13
cras at dovecot.org
cras at dovecot.org
Sun Sep 25 13:19:54 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv6769
Modified Files:
ioloop-epoll.c ioloop-poll.c ioloop-select.c ioloop.h
Log Message:
Added IO_ERROR condition that we can watch now.
Index: ioloop-epoll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-epoll.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ioloop-epoll.c 24 Sep 2005 16:32:54 -0000 1.6
+++ ioloop-epoll.c 25 Sep 2005 10:19:51 -0000 1.7
@@ -26,6 +26,7 @@
enum {
EPOLL_LIST_INPUT,
EPOLL_LIST_OUTPUT,
+ EPOLL_LIST_ERROR,
EPOLL_IOS_PER_FD
};
@@ -76,8 +77,9 @@
p_free(ioloop->pool, ioloop->handler_context);
}
-#define IO_EPOLL_INPUT (EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP)
-#define IO_EPOLL_OUTPUT (EPOLLOUT | EPOLLERR | EPOLLHUP)
+#define IO_EPOLL_ERROR (EPOLLERR | EPOLLHUP)
+#define IO_EPOLL_INPUT (EPOLLIN | EPOLLPRI | IO_EPOLL_ERROR)
+#define IO_EPOLL_OUTPUT (EPOLLOUT | IO_EPOLL_ERROR)
static int epoll_event_mask(struct io_list *list)
{
@@ -94,6 +96,8 @@
events |= IO_EPOLL_INPUT;
if (io->condition & IO_WRITE)
events |= IO_EPOLL_OUTPUT;
+ if (io->condition & IO_ERROR)
+ events |= IO_EPOLL_ERROR;
}
return events;
@@ -101,34 +105,43 @@
static int iolist_add(struct io_list *list, struct io *io)
{
- if ((io->condition & IO_READ) != 0) {
- i_assert(list->ios[EPOLL_LIST_INPUT] == NULL);
- list->ios[EPOLL_LIST_INPUT] = io;
- return list->ios[EPOLL_LIST_OUTPUT] == NULL;
+ int i, idx;
+
+ if ((io->condition & IO_READ) != 0)
+ idx = EPOLL_LIST_INPUT;
+ else if ((io->condition & IO_WRITE) != 0)
+ idx = EPOLL_LIST_OUTPUT;
+ else if ((io->condition & IO_ERROR) != 0)
+ idx = EPOLL_LIST_ERROR;
+ else {
+ i_unreached();
}
- if ((io->condition & IO_WRITE) != 0) {
- i_assert(list->ios[EPOLL_LIST_OUTPUT] == NULL);
- list->ios[EPOLL_LIST_OUTPUT] = io;
- return list->ios[EPOLL_LIST_INPUT] == NULL;
+
+ i_assert(list->ios[idx] == NULL);
+ list->ios[idx] = io;
+
+ /* check if this was the first one */
+ for (i = 0; i < EPOLL_IOS_PER_FD; i++) {
+ if (i != idx && list->ios[i] != NULL)
+ return FALSE;
}
- i_unreached();
return TRUE;
}
static int iolist_del(struct io_list *list, struct io *io)
{
- if (list->ios[EPOLL_LIST_INPUT] == io) {
- list->ios[EPOLL_LIST_INPUT] = NULL;
- return list->ios[EPOLL_LIST_OUTPUT] == NULL;
- }
- if (list->ios[EPOLL_LIST_OUTPUT] == io) {
- list->ios[EPOLL_LIST_OUTPUT] = NULL;
- return list->ios[EPOLL_LIST_INPUT] == NULL;
- }
+ int i, last = TRUE;
- i_unreached();
- return TRUE;
+ for (i = 0; i < EPOLL_IOS_PER_FD; i++) {
+ if (list->ios[i] != NULL) {
+ if (list->ios[i] == io)
+ list->ios[i] = NULL;
+ else
+ last = TRUE;
+ }
+ }
+ return last;
}
void io_loop_handle_add(struct ioloop *ioloop, struct io *io)
@@ -221,13 +234,14 @@
continue;
call = FALSE;
- if ((event->events & (EPOLLHUP | EPOLLERR)) != 0) {
+ if ((event->events & (EPOLLHUP | EPOLLERR)) != 0)
call = TRUE;
- } else if ((io->condition & IO_READ) != 0) {
- call = event->events & EPOLLIN;
- } else if ((io->condition & IO_WRITE) != 0) {
- call = event->events & EPOLLOUT;
- }
+ else if ((io->condition & IO_READ) != 0)
+ call = (event->events & EPOLLIN) != 0;
+ else if ((io->condition & IO_WRITE) != 0)
+ call = (event->events & EPOLLOUT) != 0;
+ else if ((io->condition & IO_ERROR) != 0)
+ call = (event->events & IO_EPOLL_ERROR) != 0;
if (call) {
t_id = t_push();
Index: ioloop-poll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-poll.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- ioloop-poll.c 14 Aug 2005 18:18:35 -0000 1.27
+++ ioloop-poll.c 25 Sep 2005 10:19:51 -0000 1.28
@@ -42,8 +42,9 @@
p_free(ioloop->pool, ioloop->handler_context);
}
-#define IO_POLL_INPUT (POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL)
-#define IO_POLL_OUTPUT (POLLOUT|POLLERR|POLLHUP|POLLNVAL)
+#define IO_POLL_ERROR (POLLERR|POLLHUP|POLLNVAL)
+#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 *io)
{
@@ -95,6 +96,8 @@
ctx->fds[index].events |= IO_POLL_INPUT;
if (condition & IO_WRITE)
ctx->fds[index].events |= IO_POLL_OUTPUT;
+ if (condition & IO_ERROR)
+ ctx->fds[index].events |= IO_POLL_ERROR;
}
void io_loop_handle_remove(struct ioloop *ioloop, struct io *io)
@@ -172,6 +175,9 @@
} else if (io->condition & IO_WRITE) {
call = (pollfd->revents & IO_POLL_OUTPUT) != 0;
pollfd->revents &= ~IO_POLL_OUTPUT;
+ } else if (io->condition & IO_ERROR) {
+ call = (pollfd->revents & IO_POLL_ERROR) != 0;
+ pollfd->revents &= ~IO_POLL_ERROR;
} else {
call = FALSE;
}
Index: ioloop-select.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-select.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- ioloop-select.c 14 Aug 2005 18:18:35 -0000 1.21
+++ ioloop-select.c 25 Sep 2005 10:19:51 -0000 1.22
@@ -13,10 +13,10 @@
struct ioloop_handler_context {
int highest_fd;
- fd_set read_fds, write_fds;
+ fd_set read_fds, write_fds, except_fds;
};
-static fd_set tmp_read_fds, tmp_write_fds;
+static fd_set tmp_read_fds, tmp_write_fds, tmp_except_fds;
static void update_highest_fd(struct ioloop *ioloop)
{
@@ -44,6 +44,7 @@
ioloop->handler_context->highest_fd = -1;
FD_ZERO(&ioloop->handler_context->read_fds);
FD_ZERO(&ioloop->handler_context->write_fds);
+ FD_ZERO(&ioloop->handler_context->except_fds);
}
void io_loop_handler_deinit(struct ioloop *ioloop)
@@ -65,6 +66,7 @@
FD_SET(fd, &ioloop->handler_context->read_fds);
if (condition & IO_WRITE)
FD_SET(fd, &ioloop->handler_context->write_fds);
+ FD_SET(fd, &ioloop->handler_context->except_fds);
if (io->fd > ioloop->handler_context->highest_fd)
ioloop->handler_context->highest_fd = io->fd;
@@ -82,14 +84,20 @@
if (condition & IO_WRITE)
FD_CLR(fd, &ioloop->handler_context->write_fds);
- /* check if we removed the highest fd */
- if (io->fd == ioloop->handler_context->highest_fd)
- update_highest_fd(ioloop);
+ if (!FD_ISSET(fd, &ioloop->handler_context->read_fds) &&
+ !FD_ISSET(fd, &ioloop->handler_context->write_fds)) {
+ FD_CLR(fd, &ioloop->handler_context->except_fds);
+
+ /* check if we removed the highest fd */
+ if (io->fd == ioloop->handler_context->highest_fd)
+ update_highest_fd(ioloop);
+ }
}
#define io_check_condition(fd, condition) \
((FD_ISSET((fd), &tmp_read_fds) && ((condition) & IO_READ)) || \
- (FD_ISSET((fd), &tmp_write_fds) && ((condition) & IO_WRITE)))
+ (FD_ISSET((fd), &tmp_write_fds) && ((condition) & IO_WRITE)) || \
+ (FD_ISSET((fd), &tmp_except_fds)))
void io_loop_handler_run(struct ioloop *ioloop)
{
@@ -105,9 +113,11 @@
sizeof(fd_set));
memcpy(&tmp_write_fds, &ioloop->handler_context->write_fds,
sizeof(fd_set));
+ memcpy(&tmp_except_fds, &ioloop->handler_data->except_fds,
+ sizeof(fd_set));
ret = select(ioloop->handler_context->highest_fd + 1,
- &tmp_read_fds, &tmp_write_fds, NULL, &tv);
+ &tmp_read_fds, &tmp_write_fds, &tmp_except_fds, &tv);
if (ret < 0 && errno != EINTR)
i_warning("select() : %m");
Index: ioloop.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ioloop.h 14 Aug 2005 21:54:20 -0000 1.12
+++ ioloop.h 25 Sep 2005 10:19:51 -0000 1.13
@@ -11,6 +11,7 @@
enum io_condition {
IO_READ = 0x01,
IO_WRITE = 0x02,
+ IO_ERROR = 0x04,
/* internal */
IO_NOTIFY = 0x04,
More information about the dovecot-cvs
mailing list