[dovecot-cvs] dovecot/src/lib ioloop-epoll.c, 1.3, 1.4 ioloop-internal.h, 1.13, 1.14 ioloop-poll.c, 1.25, 1.26 ioloop-select.c, 1.19, 1.20

cras at dovecot.org cras at dovecot.org
Tue Jul 12 18:44:51 EEST 2005


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

Modified Files:
	ioloop-epoll.c ioloop-internal.h ioloop-poll.c ioloop-select.c 
Log Message:
data -> context/ctx naming convention replaces



Index: ioloop-epoll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-epoll.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ioloop-epoll.c	12 Mar 2005 23:10:33 -0000	1.3
+++ ioloop-epoll.c	12 Jul 2005 15:44:49 -0000	1.4
@@ -28,7 +28,7 @@
 	EPOLL_IOS_PER_FD
 };
 
-struct ioloop_handler_data {
+struct ioloop_handler_context {
 	int epfd;
 	int events_size, events_pos;
 	struct epoll_event *events;
@@ -43,32 +43,32 @@
 
 void io_loop_handler_init(struct ioloop *ioloop)
 {
-	struct ioloop_handler_data *data;
+	struct ioloop_handler_context *ctx;
 
-	ioloop->handler_data = data =
-		p_new(ioloop->pool, struct ioloop_handler_data, 1);
+	ioloop->handler_context = ctx =
+		p_new(ioloop->pool, struct ioloop_handler_context, 1);
 
-	data->events_pos = 0;
-	data->events_size = INITIAL_EPOLL_EVENTS;
-	data->events = p_new(ioloop->pool, struct epoll_event,
-			     data->events_size);
+	ctx->events_pos = 0;
+	ctx->events_size = INITIAL_EPOLL_EVENTS;
+	ctx->events = p_new(ioloop->pool, struct epoll_event,
+			    ctx->events_size);
 
-	data->idx_size = INITIAL_EPOLL_EVENTS;
-	data->fd_index = p_new(ioloop->pool, struct io_list *, data->idx_size);
+	ctx->idx_size = INITIAL_EPOLL_EVENTS;
+	ctx->fd_index = p_new(ioloop->pool, struct io_list *, ctx->idx_size);
 
-	data->epfd = epoll_create(INITIAL_EPOLL_EVENTS);
-	if (data->epfd < 0)
+	ctx->epfd = epoll_create(INITIAL_EPOLL_EVENTS);
+	if (ctx->epfd < 0)
 		i_fatal("epoll_create(): %m");
 }
 
 void io_loop_handler_deinit(struct ioloop *ioloop)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
 
-	close(data->epfd);
-	p_free(ioloop->pool, ioloop->handler_data->events);
-	p_free(ioloop->pool, ioloop->handler_data->fd_index);
-	p_free(ioloop->pool, ioloop->handler_data);
+	close(ctx->epfd);
+	p_free(ioloop->pool, ioloop->handler_context->events);
+	p_free(ioloop->pool, ioloop->handler_context->fd_index);
+	p_free(ioloop->pool, ioloop->handler_context);
 }
 
 #define IO_EPOLL_INPUT	(EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP)
@@ -128,27 +128,27 @@
 
 void io_loop_handle_add(struct ioloop *ioloop, struct io *io)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
 	struct io_list *list;
 	struct epoll_event event;
 	int ret, first, op, fd = io->fd;
 
-	list = data->fd_index[fd];
+	list = ctx->fd_index[fd];
 	if (list == NULL) {
-		if ((unsigned int) fd >= data->idx_size) {
+		if ((unsigned int) fd >= ctx->idx_size) {
                 	/* grow the fd -> iolist array */
-			unsigned int old_size = data->idx_size;
+			unsigned int old_size = ctx->idx_size;
 
-			data->idx_size = nearest_power((unsigned int) fd+1);
+			ctx->idx_size = nearest_power((unsigned int) fd+1);
 
-			i_assert(data->idx_size < (size_t)-1 / sizeof(int));
+			i_assert(ctx->idx_size < (size_t)-1 / sizeof(int));
 
-			data->fd_index = p_realloc(ioloop->pool, data->fd_index,
-						   sizeof(int) * old_size,
-						   sizeof(int) * data->idx_size);
+			ctx->fd_index = p_realloc(ioloop->pool, ctx->fd_index,
+						  sizeof(int) * old_size,
+						  sizeof(int) * ctx->idx_size);
 		}
 
-		data->fd_index[fd] = list =
+		ctx->fd_index[fd] = list =
 			p_new(ioloop->pool, struct io_list, 1);
 	}
 
@@ -159,25 +159,25 @@
 
 	op = first ? EPOLL_CTL_ADD : EPOLL_CTL_MOD;
 
-	ret = epoll_ctl(data->epfd, op, fd, &event);
+	ret = epoll_ctl(ctx->epfd, op, fd, &event);
 	if (ret < 0)
 		i_fatal("epoll_ctl(): %m");
 
-	if (data->events_pos >= data->events_size) {
-		data->events_size = nearest_power(data->events_size + 1);
+	if (ctx->events_pos >= ctx->events_size) {
+		ctx->events_size = nearest_power(ctx->events_size + 1);
 
-		p_free(ioloop->pool, data->events);
-		data->events = p_new(ioloop->pool, struct epoll_event,
-				     data->events_size);
+		p_free(ioloop->pool, ctx->events);
+		ctx->events = p_new(ioloop->pool, struct epoll_event,
+				    ctx->events_size);
 	}
 
-	data->events_pos++;
+	ctx->events_pos++;
 }
 
 void io_loop_handle_remove(struct ioloop *ioloop, struct io *io)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
-	struct io_list *list = data->fd_index[io->fd];
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
+	struct io_list *list = ctx->fd_index[io->fd];
 	struct epoll_event event;
 	int ret, last, op;
 
@@ -188,16 +188,16 @@
 
 	op = last ? EPOLL_CTL_DEL : EPOLL_CTL_MOD;
 
-	ret = epoll_ctl(data->epfd, op, io->fd, &event);
+	ret = epoll_ctl(ctx->epfd, op, io->fd, &event);
 	if (ret < 0 && errno != EBADF)
 		i_fatal("epoll_ctl(): %m");
 
-	data->events_pos--;
+	ctx->events_pos--;
 }
 
 void io_loop_handler_run(struct ioloop *ioloop)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
 	struct epoll_event *event;
 	struct io_list *list;
 	struct io *io;
@@ -208,7 +208,7 @@
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
 
-	ret = epoll_wait(data->epfd, data->events, data->events_size, msecs);
+	ret = epoll_wait(ctx->epfd, ctx->events, ctx->events_size, msecs);
 	if (ret < 0 && errno != EINTR)
 		i_fatal("epoll_wait(): %m");
 
@@ -220,7 +220,7 @@
 		return;
 	}
 
-	event = data->events;
+	event = ctx->events;
 	while (ret-- > 0) {
 		list = event->data.ptr;
 

Index: ioloop-internal.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-internal.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ioloop-internal.h	12 Jul 2005 15:40:33 -0000	1.13
+++ ioloop-internal.h	12 Jul 2005 15:44:49 -0000	1.14
@@ -13,7 +13,7 @@
 	struct io *next_io;
 	struct timeout *timeouts; /* sorted by next_run */
 
-        struct ioloop_handler_data *handler_data;
+        struct ioloop_handler_context *handler_context;
         struct ioloop_notify_handler_context *notify_handler_context;
 
 	unsigned int running:1;

Index: ioloop-poll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-poll.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ioloop-poll.c	17 Apr 2005 14:57:18 -0000	1.25
+++ ioloop-poll.c	12 Jul 2005 15:44:49 -0000	1.26
@@ -13,7 +13,7 @@
 #  define INITIAL_POLL_FDS 128
 #endif
 
-struct ioloop_handler_data {
+struct ioloop_handler_context {
 	unsigned int fds_size, fds_pos;
 	struct pollfd *fds;
 
@@ -23,23 +23,23 @@
 
 void io_loop_handler_init(struct ioloop *ioloop)
 {
-	struct ioloop_handler_data *data;
+	struct ioloop_handler_context *ctx;
 
-	ioloop->handler_data = data =
-		p_new(ioloop->pool, struct ioloop_handler_data, 1);
-	data->fds_size = INITIAL_POLL_FDS;
-	data->fds = p_new(ioloop->pool, struct pollfd, data->fds_size);
+	ioloop->handler_context = ctx =
+		p_new(ioloop->pool, struct ioloop_handler_context, 1);
+	ctx->fds_size = INITIAL_POLL_FDS;
+	ctx->fds = p_new(ioloop->pool, struct pollfd, ctx->fds_size);
 
-	data->idx_size = INITIAL_POLL_FDS;
-	data->fd_index = p_new(ioloop->pool, int, data->idx_size);
-        memset(data->fd_index, 0xff, sizeof(int) * data->idx_size);
+	ctx->idx_size = INITIAL_POLL_FDS;
+	ctx->fd_index = p_new(ioloop->pool, int, ctx->idx_size);
+        memset(ctx->fd_index, 0xff, sizeof(int) * ctx->idx_size);
 }
 
 void io_loop_handler_deinit(struct ioloop *ioloop)
 {
-        p_free(ioloop->pool, ioloop->handler_data->fds);
-        p_free(ioloop->pool, ioloop->handler_data->fd_index);
-        p_free(ioloop->pool, ioloop->handler_data);
+        p_free(ioloop->pool, ioloop->handler_context->fds);
+        p_free(ioloop->pool, ioloop->handler_context->fd_index);
+        p_free(ioloop->pool, ioloop->handler_context);
 }
 
 #define IO_POLL_INPUT (POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL)
@@ -47,89 +47,89 @@
 
 void io_loop_handle_add(struct ioloop *ioloop, struct io *io)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
 	enum io_condition condition = io->condition;
 	unsigned int old_size;
 	int index, fd = io->fd;
 
-	if ((unsigned int) fd >= data->idx_size) {
+	if ((unsigned int)fd >= ctx->idx_size) {
                 /* grow the fd -> index array */
-		old_size = data->idx_size;
+		old_size = ctx->idx_size;
 
-		data->idx_size = nearest_power((unsigned int) fd+1);
-		i_assert(data->idx_size < (size_t)-1 / sizeof(int));
+		ctx->idx_size = nearest_power((unsigned int) fd+1);
+		i_assert(ctx->idx_size < (size_t)-1 / sizeof(int));
 
-		data->fd_index = p_realloc(ioloop->pool, data->fd_index,
-					   sizeof(int) * old_size,
-					   sizeof(int) * data->idx_size);
-		memset(data->fd_index + old_size, 0xff,
-		       sizeof(int) * (data->idx_size-old_size));
+		ctx->fd_index = p_realloc(ioloop->pool, ctx->fd_index,
+					  sizeof(int) * old_size,
+					  sizeof(int) * ctx->idx_size);
+		memset(ctx->fd_index + old_size, 0xff,
+		       sizeof(int) * (ctx->idx_size-old_size));
 	}
 
-	if (data->fds_pos >= data->fds_size) {
+	if (ctx->fds_pos >= ctx->fds_size) {
 		/* grow the fd array */
-		old_size = data->fds_size;
+		old_size = ctx->fds_size;
 
-		data->fds_size = nearest_power(data->fds_size+1);
-		i_assert(data->fds_size < (size_t)-1 / sizeof(struct pollfd));
+		ctx->fds_size = nearest_power(ctx->fds_size+1);
+		i_assert(ctx->fds_size < (size_t)-1 / sizeof(struct pollfd));
 
-		data->fds = p_realloc(ioloop->pool, data->fds,
-				      sizeof(struct pollfd) * old_size,
-				      sizeof(struct pollfd) * data->fds_size);
+		ctx->fds = p_realloc(ioloop->pool, ctx->fds,
+				     sizeof(struct pollfd) * old_size,
+				     sizeof(struct pollfd) * ctx->fds_size);
 	}
 
-	if (data->fd_index[fd] != -1) {
+	if (ctx->fd_index[fd] != -1) {
 		/* update existing pollfd */
-                index = data->fd_index[fd];
+                index = ctx->fd_index[fd];
 	} else {
                 /* add new pollfd */
-                index = data->fds_pos++;
+                index = ctx->fds_pos++;
 
-		data->fd_index[fd] = index;
-		data->fds[index].fd = fd;
-		data->fds[index].events = 0;
-		data->fds[index].revents = 0;
+		ctx->fd_index[fd] = index;
+		ctx->fds[index].fd = fd;
+		ctx->fds[index].events = 0;
+		ctx->fds[index].revents = 0;
 	}
 
         if (condition & IO_READ)
-		data->fds[index].events |= IO_POLL_INPUT;
+		ctx->fds[index].events |= IO_POLL_INPUT;
         if (condition & IO_WRITE)
-		data->fds[index].events |= IO_POLL_OUTPUT;
+		ctx->fds[index].events |= IO_POLL_OUTPUT;
 }
 
 void io_loop_handle_remove(struct ioloop *ioloop,  struct io *io)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
 	enum io_condition condition = io->condition;
 	int index, fd = io->fd;
 
-	index = data->fd_index[fd];
-	i_assert(index >= 0 && (unsigned int) index < data->fds_size);
+	index = ctx->fd_index[fd];
+	i_assert(index >= 0 && (unsigned int) index < ctx->fds_size);
 
 	if (condition & IO_READ) {
-		data->fds[index].events &= ~(POLLIN|POLLPRI);
-		data->fds[index].revents &= ~(POLLIN|POLLPRI);
+		ctx->fds[index].events &= ~(POLLIN|POLLPRI);
+		ctx->fds[index].revents &= ~(POLLIN|POLLPRI);
 	}
 	if (condition & IO_WRITE) {
-		data->fds[index].events &= ~POLLOUT;
-		data->fds[index].revents &= ~POLLOUT;
+		ctx->fds[index].events &= ~POLLOUT;
+		ctx->fds[index].revents &= ~POLLOUT;
 	}
 
-	if ((data->fds[index].events & (POLLIN|POLLOUT)) == 0) {
+	if ((ctx->fds[index].events & (POLLIN|POLLOUT)) == 0) {
 		/* remove the whole pollfd */
-		data->fd_index[data->fds[index].fd] = -1;
-		if (--data->fds_pos == (unsigned int) index)
+		ctx->fd_index[ctx->fds[index].fd] = -1;
+		if (--ctx->fds_pos == (unsigned int) index)
                         return; /* removing last one */
 
                 /* move the last pollfd over the removed one */
-		data->fds[index] = data->fds[data->fds_pos];
-		data->fd_index[data->fds[index].fd] = index;
+		ctx->fds[index] = ctx->fds[ctx->fds_pos];
+		ctx->fd_index[ctx->fds[index].fd] = index;
 	}
 }
 
 void io_loop_handler_run(struct ioloop *ioloop)
 {
-	struct ioloop_handler_data *data = ioloop->handler_data;
+	struct ioloop_handler_context *ctx = ioloop->handler_context;
         struct pollfd *pollfd;
         struct timeval tv;
 	struct io *io;
@@ -139,7 +139,7 @@
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
 
-	ret = poll(data->fds, data->fds_pos, msecs);
+	ret = poll(ctx->fds, ctx->fds_pos, msecs);
 	if (ret < 0 && errno != EINTR)
 		i_fatal("poll(): %m");
 
@@ -154,7 +154,7 @@
 	for (io = ioloop->ios; io != NULL && ret > 0; io = ioloop->next_io) {
 		ioloop->next_io = io->next;
 
-		pollfd = &data->fds[data->fd_index[io->fd]];
+		pollfd = &ctx->fds[ctx->fd_index[io->fd]];
 		if (pollfd->revents != 0) {
 			if (pollfd->revents & POLLNVAL) {
 				i_error("invalid I/O fd %d, callback %p",

Index: ioloop-select.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-select.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ioloop-select.c	25 Aug 2004 12:27:44 -0000	1.19
+++ ioloop-select.c	12 Jul 2005 15:44:49 -0000	1.20
@@ -11,7 +11,7 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-struct ioloop_handler_data {
+struct ioloop_handler_context {
 	int highest_fd;
 	fd_set read_fds, write_fds;
 };
@@ -23,31 +23,32 @@
         struct io *io;
 	int max_highest_fd;
 
-        max_highest_fd = ioloop->handler_data->highest_fd-1;
-	ioloop->handler_data->highest_fd = -1;
+        max_highest_fd = ioloop->handler_context->highest_fd-1;
+	ioloop->handler_context->highest_fd = -1;
 
 	for (io = ioloop->ios; io != NULL; io = io->next) {
-		if (io->fd > ioloop->handler_data->highest_fd) {
-			ioloop->handler_data->highest_fd = io->fd;
+		if (io->fd <= ioloop->handler_context->highest_fd)
+			continue;
 
-			if (ioloop->handler_data->highest_fd == max_highest_fd)
-                                break;
-		}
+		ioloop->handler_context->highest_fd = io->fd;
+
+		if (ioloop->handler_context->highest_fd == max_highest_fd)
+			break;
 	}
 }
 
 void io_loop_handler_init(struct ioloop *ioloop)
 {
-	ioloop->handler_data =
-		p_new(ioloop->pool, struct ioloop_handler_data, 1);
-	ioloop->handler_data->highest_fd = -1;
-        FD_ZERO(&ioloop->handler_data->read_fds);
-	FD_ZERO(&ioloop->handler_data->write_fds);
+	ioloop->handler_context =
+		p_new(ioloop->pool, struct ioloop_handler_context, 1);
+	ioloop->handler_context->highest_fd = -1;
+        FD_ZERO(&ioloop->handler_context->read_fds);
+	FD_ZERO(&ioloop->handler_context->write_fds);
 }
 
 void io_loop_handler_deinit(struct ioloop *ioloop)
 {
-        p_free(ioloop->pool, ioloop->handler_data);
+        p_free(ioloop->pool, ioloop->handler_context);
 }
 
 void io_loop_handle_add(struct ioloop *ioloop, struct io *io)
@@ -61,12 +62,12 @@
 		i_fatal("fd %d too large for select()", fd);
 
         if (condition & IO_READ)
-		FD_SET(fd, &ioloop->handler_data->read_fds);
+		FD_SET(fd, &ioloop->handler_context->read_fds);
         if (condition & IO_WRITE)
-		FD_SET(fd, &ioloop->handler_data->write_fds);
+		FD_SET(fd, &ioloop->handler_context->write_fds);
 
-	if (io->fd > ioloop->handler_data->highest_fd)
-		ioloop->handler_data->highest_fd = io->fd;
+	if (io->fd > ioloop->handler_context->highest_fd)
+		ioloop->handler_context->highest_fd = io->fd;
 }
 
 void io_loop_handle_remove(struct ioloop *ioloop, struct io *io)
@@ -77,12 +78,12 @@
 	i_assert(fd >= 0 && fd < FD_SETSIZE);
 
         if (condition & IO_READ)
-		FD_CLR(fd, &ioloop->handler_data->read_fds);
+		FD_CLR(fd, &ioloop->handler_context->read_fds);
         if (condition & IO_WRITE)
-		FD_CLR(fd, &ioloop->handler_data->write_fds);
+		FD_CLR(fd, &ioloop->handler_context->write_fds);
 
 	/* check if we removed the highest fd */
-	if (io->fd == ioloop->handler_data->highest_fd)
+	if (io->fd == ioloop->handler_context->highest_fd)
 		update_highest_fd(ioloop);
 }
 
@@ -100,11 +101,12 @@
 	/* get the time left for next timeout task */
 	io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
 
-        memcpy(&tmp_read_fds, &ioloop->handler_data->read_fds, sizeof(fd_set));
-	memcpy(&tmp_write_fds, &ioloop->handler_data->write_fds,
+	memcpy(&tmp_read_fds, &ioloop->handler_context->read_fds,
+	       sizeof(fd_set));
+	memcpy(&tmp_write_fds, &ioloop->handler_context->write_fds,
 	       sizeof(fd_set));
 
-	ret = select(ioloop->handler_data->highest_fd + 1,
+	ret = select(ioloop->handler_context->highest_fd + 1,
 		     &tmp_read_fds, &tmp_write_fds, NULL, &tv);
 	if (ret < 0 && errno != EINTR)
 		i_warning("select() : %m");



More information about the dovecot-cvs mailing list