[Dovecot] [PATCH] move highest_fd calculations to ioloop-select.c

Andrey Panin pazke at donpac.ru
Wed Aug 25 14:13:29 EEST 2004


Hello,

ioloop->highest_fd is used by ioloop-select.c only, so its
handling can be moved out of generic ioloop code. Attached
patch (agains -test35) does exactly this.

Please consider applying.

Best regards.

-- 
Andrey Panin		| Linux and UNIX system administrator
pazke at donpac.ru		| PGP key: wwwkeys.pgp.net
-------------- next part --------------
diff -urpNX /usr/share/dontdiff -x Makefile dovecot-1.0-test35.vanilla/src/lib/ioloop.c dovecot-1.0-test35/src/lib/ioloop.c
--- dovecot-1.0-test35.vanilla/src/lib/ioloop.c	2004-08-23 17:46:41.000000000 +0400
+++ dovecot-1.0-test35/src/lib/ioloop.c	2004-08-25 10:32:08.000000000 +0400
@@ -15,24 +15,6 @@ struct timezone ioloop_timezone;
 
 static struct ioloop *current_ioloop = NULL;
 
-static void update_highest_fd(struct ioloop *ioloop)
-{
-        struct io *io;
-	int max_highest_fd;
-
-        max_highest_fd = ioloop->highest_fd-1;
-	ioloop->highest_fd = -1;
-
-	for (io = ioloop->ios; io != NULL; io = io->next) {
-		if (!io->destroyed && io->fd > ioloop->highest_fd) {
-			ioloop->highest_fd = io->fd;
-
-			if (ioloop->highest_fd == max_highest_fd)
-                                break;
-		}
-	}
-}
-
 struct io *io_add(int fd, enum io_condition condition,
 		  io_callback_t *callback, void *context)
 {
@@ -53,9 +35,6 @@ struct io *io_add(int fd, enum io_condit
 	io->callback = callback;
         io->context = context;
 
-	if (io->fd > current_ioloop->highest_fd)
-		current_ioloop->highest_fd = io->fd;
-
 	io_loop_handle_add(current_ioloop, io);
 
 	/* have to append it, or io_destroy() breaks */
@@ -76,17 +55,11 @@ void io_remove(struct io *io)
 		return;
 	}
 
-	i_assert(io->fd <= current_ioloop->highest_fd);
-
 	/* notify the real I/O handler */
 	io_loop_handle_remove(current_ioloop, io);
 
 	io->destroyed = TRUE;
 
-	/* check if we removed the highest fd */
-	if (io->fd == current_ioloop->highest_fd)
-		update_highest_fd(current_ioloop);
-
 	io->fd = -1;
 }
 
@@ -275,7 +248,6 @@ struct ioloop *io_loop_create(pool_t poo
         ioloop = p_new(pool, struct ioloop, 1);
 	pool_ref(pool);
 	ioloop->pool = pool;
-	ioloop->highest_fd = -1;
 
 	io_loop_handler_init(ioloop);
 
diff -urpNX /usr/share/dontdiff -x Makefile dovecot-1.0-test35.vanilla/src/lib/ioloop-select.c dovecot-1.0-test35/src/lib/ioloop-select.c
--- dovecot-1.0-test35.vanilla/src/lib/ioloop-select.c	2004-08-23 17:46:41.000000000 +0400
+++ dovecot-1.0-test35/src/lib/ioloop-select.c	2004-08-25 10:55:25.000000000 +0400
@@ -17,8 +17,27 @@ struct ioloop_handler_data {
 
 static fd_set tmp_read_fds, tmp_write_fds;
 
+static void update_highest_fd(struct ioloop *ioloop)
+{
+        struct io *io;
+	int max_highest_fd;
+
+        max_highest_fd = ioloop->highest_fd-1;
+	ioloop->highest_fd = -1;
+
+	for (io = ioloop->ios; io != NULL; io = io->next) {
+		if (!io->destroyed && io->fd > ioloop->highest_fd) {
+			ioloop->highest_fd = io->fd;
+
+			if (ioloop->highest_fd == max_highest_fd)
+                                break;
+		}
+	}
+}
+
 void io_loop_handler_init(struct ioloop *ioloop)
 {
+	ioloop->highest_fd = -1;
 	ioloop->handler_data =
 		p_new(ioloop->pool, struct ioloop_handler_data, 1);
         FD_ZERO(&ioloop->handler_data->read_fds);
@@ -44,6 +63,9 @@ void io_loop_handle_add(struct ioloop *i
 		FD_SET(fd, &ioloop->handler_data->read_fds);
         if (condition & IO_WRITE)
 		FD_SET(fd, &ioloop->handler_data->write_fds);
+
+	if (io->fd > ioloop->highest_fd)
+		ioloop->highest_fd = io->fd;
 }
 
 void io_loop_handle_remove(struct ioloop *ioloop, struct io *io)
@@ -57,6 +79,10 @@ void io_loop_handle_remove(struct ioloop
 		FD_CLR(fd, &ioloop->handler_data->read_fds);
         if (condition & IO_WRITE)
 		FD_CLR(fd, &ioloop->handler_data->write_fds);
+
+	/* check if we removed the highest fd */
+	if (io->fd == ioloop->highest_fd)
+		update_highest_fd(ioloop);
 }
 
 #define io_check_condition(fd, condition) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://dovecot.org/pipermail/dovecot/attachments/20040825/a1157f42/attachment-0001.bin>


More information about the dovecot mailing list