[dovecot-cvs] dovecot/src/lib ioloop-epoll.c, 1.11.2.2, 1.11.2.3 ioloop-kqueue.c, 1.4.2.3, 1.4.2.4

cras at dovecot.org cras at dovecot.org
Thu Aug 17 00:33:40 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv4165

Modified Files:
      Tag: branch_1_0
	ioloop-epoll.c ioloop-kqueue.c 
Log Message:
Fixes



Index: ioloop-epoll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-epoll.c,v
retrieving revision 1.11.2.2
retrieving revision 1.11.2.3
diff -u -d -r1.11.2.2 -r1.11.2.3
--- ioloop-epoll.c	16 Aug 2006 15:54:56 -0000	1.11.2.2
+++ ioloop-epoll.c	16 Aug 2006 21:33:38 -0000	1.11.2.3
@@ -146,35 +146,37 @@
 void io_loop_handler_run(struct ioloop *ioloop)
 {
 	struct ioloop_handler_context *ctx = ioloop->handler_context;
-	struct epoll_event *event;
+	struct epoll_event *events;
+	const struct epoll_event *event;
 	struct io_list *list;
 	struct io *io;
 	struct timeval tv;
 	unsigned int events_count, t_id;
-	int msecs, ret, i;
+	int msecs, ret, i, j;
 	bool call;
 
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
 
-	event = array_get_modifyable(&ctx->events, &events_count);
-	ret = epoll_wait(ctx->epfd, event, events_count, msecs);
+	events = array_get_modifyable(&ctx->events, &events_count);
+	ret = epoll_wait(ctx->epfd, events, events_count, msecs);
 	if (ret < 0 && errno != EINTR)
 		i_fatal("epoll_wait(): %m");
 
 	/* execute timeout handlers */
         io_loop_handle_timeouts(ioloop);
 
-	if (ret <= 0 || !ioloop->running) {
-		/* No events */
+	if (!ioloop->running)
 		return;
-	}
 
-	while (ret-- > 0) {
+	for (i = 0; i < ret; i++) {
+		/* io_loop_handle_add() may cause events array reallocation,
+		   so we have use array_idx() */
+		event = array_idx(&ctx->events, i);
 		list = event->data.ptr;
 
-		for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
-			io = list->ios[i];
+		for (j = 0; j < IOLOOP_IOLIST_IOS_PER_FD; j++) {
+			io = list->ios[j];
 			if (io == NULL)
 				continue;
 
@@ -198,7 +200,6 @@
 				}
 			}
 		}
-		event++;
 	}
 }
 

Index: ioloop-kqueue.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-kqueue.c,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -d -r1.4.2.3 -r1.4.2.4
--- ioloop-kqueue.c	16 Aug 2006 17:58:03 -0000	1.4.2.3
+++ ioloop-kqueue.c	16 Aug 2006 21:33:38 -0000	1.4.2.4
@@ -145,12 +145,13 @@
 void io_loop_handler_run(struct ioloop *ioloop)
 {
 	struct ioloop_handler_context *ctx = ioloop->handler_context;
-	struct kevent *event;
+	struct kevent *events;
+	const struct kevent *event;
 	struct timeval tv;
 	struct timespec ts;
 	struct io_list *list;
 	unsigned int events_count, t_id;
-	int msecs, ret, i;
+	int msecs, ret, i, j;
 	bool call, called;
 
 	/* get the time left for next timeout task */
@@ -159,26 +160,26 @@
 	ts.tv_nsec = tv.tv_usec * 1000;
 
 	/* wait for events */
-	event = array_get_modifyable(&ctx->events, &events_count);
-	ret = kevent (ctx->kq, NULL, 0, event, events_count, &ts);
+	events = array_get_modifyable(&ctx->events, &events_count);
+	ret = kevent (ctx->kq, NULL, 0, events, events_count, &ts);
 	if (ret < 0 && errno != EINTR)
 		i_fatal("kevent(): %m");
 
 	/* execute timeout handlers */
 	io_loop_handle_timeouts(ioloop);
 
-	if (ret <= 0 || !ioloop->running) {
-		/* no I/O events */
+	if (!ioloop->running)
 		return;
-	}
 
-	/* loop through all received events */
-	while (ret-- > 0) {
+	for (i = 0; i < ret; i++) {
+		/* io_loop_handle_add() may cause events array reallocation,
+		   so we have use array_idx() */
+		event = array_idx(&ctx->events, i);
 		list = (void *)event->udata;
 
 		called = FALSE;
-		for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
-			struct io *io = list->ios[i];
+		for (j = 0; j < IOLOOP_IOLIST_IOS_PER_FD; j++) {
+			struct io *io = list->ios[j];
 			if (io == NULL)
 				continue;
 
@@ -217,7 +218,6 @@
 				event->fflags, (unsigned long long)event->data,
 				io_list_filter(list));
 		}
-		event++;
 	}
 }
 



More information about the dovecot-cvs mailing list