changeset 1499:e850252cdc7e HEAD

Removed I/O priorities. They were pretty much useless and were just getting in way.
author Timo Sirainen <tss@iki.fi>
date Fri, 23 May 2003 17:40:49 +0300
parents 5a247fb1673c
children 40b6118245b2
files src/auth/login-connection.c src/auth/main.c src/auth/master-connection.c src/imap-login/client-authenticate.c src/imap-login/client.c src/imap/client.c src/lib-index/mbox/mbox-rewrite.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/mbox/mbox-expunge.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/subscription-file/subscription-file.c src/lib/ioloop-internal.h src/lib/ioloop-poll.c src/lib/ioloop-select.c src/lib/ioloop.c src/lib/ioloop.h src/lib/ostream-file.c src/lib/ostream.h src/login-common/auth-connection.c src/master/auth-process.c src/master/login-process.c src/master/ssl-init-openssl.c src/pop3-login/client.c src/pop3/client.c
diffstat 24 files changed, 241 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/login-connection.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/auth/login-connection.c	Fri May 23 17:40:49 2003 +0300
@@ -186,7 +186,7 @@
 	conn->input = i_stream_create_file(fd, default_pool, MAX_INBUF_SIZE,
 					   FALSE);
 	conn->output = o_stream_create_file(fd, default_pool, MAX_OUTBUF_SIZE,
-					    IO_PRIORITY_DEFAULT, FALSE);
+					    FALSE);
 	conn->io = io_add(fd, IO_READ, login_input, conn);
 
 	conn->pool = pool_alloconly_create("auth_request hash", 10240);
--- a/src/auth/main.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/auth/main.c	Fri May 23 17:40:49 2003 +0300
@@ -80,8 +80,7 @@
 
 	login_connections_init();
 
-	io_listen = io_add_priority(LOGIN_LISTEN_FD, IO_PRIORITY_LOW,
-				    IO_READ, auth_accept, NULL);
+	io_listen = io_add(LOGIN_LISTEN_FD, IO_READ, auth_accept, NULL);
 
 	/* initialize master last - it sends the "we're ok" notification */
 	master_connection_init();
--- a/src/auth/master-connection.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/auth/master-connection.c	Fri May 23 17:40:49 2003 +0300
@@ -166,8 +166,7 @@
 
 	master_pos = 0;
 	output = o_stream_create_file(MASTER_SOCKET_FD, default_pool,
-				      MAX_OUTBUF_SIZE, IO_PRIORITY_DEFAULT,
-				      FALSE);
+				      MAX_OUTBUF_SIZE, FALSE);
 	io_master = io_add(MASTER_SOCKET_FD, IO_READ, master_input, NULL);
 
 	/* just a note to master that we're ok. if we die before,
--- a/src/imap-login/client-authenticate.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/imap-login/client-authenticate.c	Fri May 23 17:40:49 2003 +0300
@@ -62,6 +62,8 @@
 
 static void client_auth_abort(struct imap_client *client, const char *msg)
 {
+	client->authenticating = FALSE;
+
 	if (client->common.auth_request != NULL) {
 		auth_abort_request(client->common.auth_request);
                 auth_request_unref(client->common.auth_request);
@@ -132,7 +134,6 @@
 			      master_callback, &error)) {
 	case -1:
 		/* login failed */
-                client->authenticating = FALSE;
 		client_auth_abort(client, error);
 		break;
 
@@ -213,7 +214,6 @@
 			      master_callback, &error)) {
 	case -1:
 		/* login failed */
-                client->authenticating = FALSE;
 		client_auth_abort(client, error);
 		break;
 
--- a/src/imap-login/client.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/imap-login/client.c	Fri May 23 17:40:49 2003 +0300
@@ -62,7 +62,7 @@
 	client->input = i_stream_create_file(fd, default_pool,
 					     MAX_INBUF_SIZE, FALSE);
 	client->output = o_stream_create_file(fd, default_pool, MAX_OUTBUF_SIZE,
-					      IO_PRIORITY_DEFAULT, FALSE);
+					      FALSE);
 	client->parser = imap_parser_create(client->input, client->output,
 					    MAX_INBUF_SIZE,
 					    MAX_IMAP_ARG_ELEMENTS);
--- a/src/imap/client.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/imap/client.c	Fri May 23 17:40:49 2003 +0300
@@ -50,8 +50,7 @@
 	client = i_new(struct client, 1);
 	client->input = i_stream_create_file(hin, default_pool,
 					     MAX_INBUF_SIZE, FALSE);
-	client->output = o_stream_create_file(hout, default_pool, 4096,
-					      IO_PRIORITY_DEFAULT, FALSE);
+	client->output = o_stream_create_file(hout, default_pool, 4096, FALSE);
 
 	/* set timeout for reading expected data (eg. APPEND). This is
 	   different from the actual idle time. */
--- a/src/lib-index/mbox/mbox-rewrite.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib-index/mbox/mbox-rewrite.c	Fri May 23 17:40:49 2003 +0300
@@ -495,7 +495,7 @@
 				     1024*256, 0, 0, FALSE);
 	i_stream_set_read_limit(input, size);
 
-	output = o_stream_create_file(out_fd, data_stack_pool, 1024, 0, FALSE);
+	output = o_stream_create_file(out_fd, data_stack_pool, 1024, FALSE);
 	o_stream_set_blocking(output, 60000, NULL, NULL);
 
 	ret = o_stream_send_istream(output, input);
@@ -643,7 +643,7 @@
 
 	/* note: we can't use data_stack_pool with output stream because it's
 	   being written to inside t_push() .. t_pop() calls */
-	output = o_stream_create_file(tmp_fd, system_pool, 8192, 0, FALSE);
+	output = o_stream_create_file(tmp_fd, system_pool, 8192, FALSE);
 	o_stream_set_blocking(output, 60000, NULL, NULL);
 
 	failed = FALSE; seq = 1;
--- a/src/lib-storage/index/maildir/maildir-save.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Fri May 23 17:40:49 2003 +0300
@@ -46,8 +46,7 @@
 	fname++;
 
 	t_push();
-	output = o_stream_create_file(fd, data_stack_pool, 4096,
-				      IO_PRIORITY_DEFAULT, FALSE);
+	output = o_stream_create_file(fd, data_stack_pool, 4096, FALSE);
 	o_stream_set_blocking(output, 60000, NULL, NULL);
 
 	if (!mail_storage_save(ibox->box.storage, path, input, output,
--- a/src/lib-storage/index/mbox/mbox-expunge.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib-storage/index/mbox/mbox-expunge.c	Fri May 23 17:40:49 2003 +0300
@@ -129,7 +129,7 @@
 
 	t_push();
 	output = o_stream_create_file(ibox->index->mbox_fd, data_stack_pool,
-				      4096, 0, FALSE);
+				      4096, FALSE);
 	o_stream_set_blocking(output, 60000, NULL, NULL);
 
 	failed = !expunge_real(ibox, rec, seq, input, output, notify);
--- a/src/lib-storage/index/mbox/mbox-save.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Fri May 23 17:40:49 2003 +0300
@@ -338,7 +338,7 @@
 	}
 
 	ctx->output = o_stream_create_file(ibox->index->mbox_fd,
-					   default_pool, 4096, 0, FALSE);
+					   default_pool, 4096, FALSE);
 	o_stream_set_blocking(ctx->output, 60000, NULL, NULL);
 	return ctx;
 }
--- a/src/lib-storage/subscription-file/subscription-file.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib-storage/subscription-file/subscription-file.c	Fri May 23 17:40:49 2003 +0300
@@ -102,7 +102,7 @@
 	fd = i_stream_get_fd(input);
 	i_assert(fd != -1);
 
-	output = o_stream_create_file(fd, default_pool, 4096, 0, 0);
+	output = o_stream_create_file(fd, default_pool, 4096, FALSE);
 	if (o_stream_seek(output, input->start_offset + input->v_offset) < 0) {
 		failed = TRUE;
 		errno = output->stream_errno;
--- a/src/lib/ioloop-internal.h	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ioloop-internal.h	Fri May 23 17:40:49 2003 +0300
@@ -18,10 +18,9 @@
 };
 
 struct io {
-	struct io *prev, *next;
+	struct io *next;
 
 	int fd;
-        int priority;
 	int condition;
 
 	unsigned int destroyed:1;
@@ -34,9 +33,10 @@
 	struct timeout *next;
 
 	struct timeval next_run;
-        int msecs;
-	int run_now;
-        int destroyed;
+        unsigned int msecs;
+
+	unsigned int run_now:1;
+	unsigned int destroyed:1;
 
 	timeout_callback_t *callback;
         void *context;
@@ -47,9 +47,9 @@
 void io_loop_handle_timeouts(struct ioloop *ioloop);
 
 /* call only when io->destroyed is TRUE */
-void io_destroy(struct ioloop *ioloop, struct io *io);
+void io_destroy(struct ioloop *ioloop, struct io **io_p);
 /* call only when timeout->destroyed is TRUE */
-void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout);
+void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p);
 
 /* I/O handler calls */
 void io_loop_handle_add(struct ioloop *ioloop, int fd, int condition);
--- a/src/lib/ioloop-poll.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ioloop-poll.c	Fri May 23 17:40:49 2003 +0300
@@ -149,9 +149,9 @@
 	struct ioloop_handler_data *data = ioloop->handler_data;
         struct pollfd *pollfd;
         struct timeval tv;
-	struct io *io, *next;
+	struct io *io, **io_p;
 	unsigned int t_id;
-	int msecs, ret;
+	int msecs, ret, call;
 
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
@@ -168,53 +168,52 @@
 		return;
 	}
 
-	/* execute the I/O handlers in prioritized order */
-	for (io = ioloop->ios; io != NULL && ret > 0; io = next) {
-		next = io->next;
-
+	io_p = &ioloop->ios;
+	for (io = ioloop->ios; io != NULL && ret > 0; io = *io_p) {
 		if (io->destroyed) {
 			/* we were destroyed, and io->fd points to
 			   -1 now, so we can't know if there was any
 			   revents left. */
-			io_destroy(ioloop, io);
+			io_destroy(ioloop, io_p);
 			continue;
 		}
 
 		i_assert(io->fd >= 0);
 
 		pollfd = &data->fds[data->fd_index[io->fd]];
-		if (pollfd->revents == 0)
-			continue;
-		ret--;
+		if (pollfd->revents != 0) {
+			ret--;
 
-		if (pollfd->revents & POLLNVAL) {
-			i_error("invalid I/O fd %d, callback %p",
-				io->fd, (void *) io->callback);
-			pollfd->events &= ~POLLNVAL;
-			pollfd->revents &= ~POLLNVAL;
-			continue;
+			if (pollfd->revents & POLLNVAL) {
+				i_error("invalid I/O fd %d, callback %p",
+					io->fd, (void *) io->callback);
+				pollfd->events &= ~POLLNVAL;
+				pollfd->revents &= ~POLLNVAL;
+				call = FALSE;
+			} else if ((io->condition &
+				    (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) {
+				call = TRUE;
+				pollfd->revents = 0;
+			} else if (io->condition & IO_READ) {
+				call = (pollfd->revents & IO_POLL_INPUT) != 0;
+				pollfd->revents &= ~IO_POLL_INPUT;
+			} else if (io->condition & IO_WRITE) {
+				call = (pollfd->revents & IO_POLL_OUTPUT) != 0;
+				pollfd->revents &= ~IO_POLL_OUTPUT;
+			}
+
+			if (call) {
+				t_id = t_push();
+				io->callback(io->context);
+				if (t_pop() != t_id)
+					i_panic("Leaked a t_pop() call!");
+
+				if (io->destroyed)
+					io_destroy(ioloop, io_p);
+			}
 		}
 
-		if ((io->condition &
-		     (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) {
-			pollfd->revents = 0;
-		} else if (io->condition & IO_READ) {
-			if ((pollfd->revents & IO_POLL_INPUT) == 0)
-				continue;
-			pollfd->revents &= ~IO_POLL_INPUT;
-		} else if (io->condition & IO_WRITE) {
-			if ((pollfd->revents & IO_POLL_OUTPUT) == 0)
-				continue;
-                        pollfd->revents &= ~IO_POLL_OUTPUT;
-		}
-
-		t_id = t_push();
-		io->callback(io->context);
-		if (t_pop() != t_id)
-			i_panic("Leaked a t_pop() call!");
-
-		if (io->destroyed)
-			io_destroy(ioloop, io);
+		io_p = &io->next;
 	}
 }
 
--- a/src/lib/ioloop-select.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ioloop-select.c	Fri May 23 17:40:49 2003 +0300
@@ -107,10 +107,8 @@
 		return;
 	}
 
-	/* execute the I/O handlers in prioritized order */
-	for (io = ioloop->ios; io != NULL && ret > 0; io = next) {
-		next = io->next;
-
+	io_p = &ioloop->ios;
+	for (io = ioloop->ios; io != NULL && ret > 0; io = *io_p) {
 		if (io->destroyed) {
 			/* we were destroyed, and io->fd points to -1 now. */
 			io_destroy(ioloop, io);
@@ -122,18 +120,19 @@
 		fd = io->fd;
 		condition = io->condition;
 
-		if (!io_check_condition(fd, condition))
-                        continue;
+		if (io_check_condition(fd, condition)) {
+			t_id = t_push();
+			io->callback(io->context);
+			if (t_pop() != t_id)
+				i_panic("Leaked a t_pop() call!");
 
-		t_id = t_push();
-		io->callback(io->context);
-		if (t_pop() != t_id)
-			i_panic("Leaked a t_pop() call!");
+			if (io->destroyed)
+				io_destroy(ioloop, io_p);
 
-		if (io->destroyed)
-			io_destroy(ioloop, io);
+			ret--;
+		}
 
-		ret--;
+		io_p = &io->next;
 	}
 }
 
--- a/src/lib/ioloop.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ioloop.c	Fri May 23 17:40:49 2003 +0300
@@ -23,9 +23,6 @@
     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-/* FIXME: inserting io is slow if there's lots of them. I should add a linked
-   list of priorities pointing to first item in the list with the priority. */
-
 #include "lib.h"
 #include "ioloop-internal.h"
 
@@ -59,38 +56,7 @@
 	}
 }
 
-static void io_list_insert(struct ioloop *ioloop, struct io *io)
-{
-	struct io *prev, *next;
-
-        prev = NULL;
-	for (next = ioloop->ios; next != NULL; next = next->next) {
-		if (next->priority >= io->priority)
-                        break;
-                prev = next;
-	}
-
-	if (prev == NULL)
-                ioloop->ios = io;
-	else {
-		io->prev = prev;
-                prev->next = io;
-	}
-
-	if (next != NULL) {
-		io->next = next;
-		next->prev = io;
-	}
-}
-
-struct io *io_add(int fd, int condition, io_callback_t *callback, void *data)
-{
-	return io_add_priority(fd, IO_PRIORITY_DEFAULT,
-			       condition, callback, data);
-}
-
-struct io *io_add_priority(int fd, int priority, int condition,
-			   io_callback_t *callback, void *context)
+struct io *io_add(int fd, int condition, io_callback_t *callback, void *context)
 {
 	struct io *io;
 
@@ -99,7 +65,6 @@
 
 	io = p_new(current_ioloop->pool, struct io, 1);
 	io->fd = fd;
-	io->priority = priority;
         io->condition = condition;
 
 	io->callback = callback;
@@ -109,8 +74,9 @@
                 current_ioloop->highest_fd = io->fd;
 
         io_loop_handle_add(current_ioloop, io->fd, io->condition);
-	io_list_insert(current_ioloop, io);
 
+	io->next = current_ioloop->ios;
+	current_ioloop->ios = io;
 	return io;
 }
 
@@ -131,17 +97,12 @@
 	io->fd = -1;
 }
 
-void io_destroy(struct ioloop *ioloop, struct io *io)
+void io_destroy(struct ioloop *ioloop, struct io **io_p)
 {
-        /* remove from list */
-	if (io->prev == NULL)
-                ioloop->ios = io->next;
-	else
-		io->prev->next = io->next;
+	struct io *io = *io_p;
 
-	if (io->next != NULL)
-		io->next->prev = io->prev;
-
+	/* remove from list */
+	*io_p = io->next;
 	p_free(ioloop->pool, io);
 }
 
@@ -183,7 +144,7 @@
 	}
 }
 
-struct timeout *timeout_add(int msecs, timeout_callback_t *callback,
+struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback,
 			    void *context)
 {
 	struct timeout *timeout;
@@ -207,16 +168,11 @@
 	timeout->destroyed = TRUE;
 }
 
-void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout)
+void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p)
 {
-	struct timeout **t;
+        struct timeout *timeout = *timeout_p;
 
-	for (t = &ioloop->timeouts; *t != NULL; t = &(*t)->next) {
-		if (*t == timeout)
-			break;
-	}
-	*t = timeout->next;
-
+	*timeout_p = timeout->next;
         p_free(ioloop->pool, timeout);
 }
 
@@ -256,7 +212,7 @@
 
 void io_loop_handle_timeouts(struct ioloop *ioloop)
 {
-	struct timeout *t, *next;
+	struct timeout *t, **t_p;
 	struct timeval tv;
         unsigned int t_id;
 
@@ -267,13 +223,13 @@
 	if (ioloop->timeouts == NULL || !ioloop->timeouts->run_now)
 		return;
 
-	for (t = ioloop->timeouts; t != NULL; t = next) {
-		next = t->next;
-
+	t_p = &ioloop->timeouts;
+	for (t = ioloop->timeouts; t != NULL; t = *t_p) {
 		if (t->destroyed) {
-                        timeout_destroy(ioloop, t);
+                        timeout_destroy(ioloop, t_p);
 			continue;
 		}
+		t_p = &t->next;
 
 		if (!t->run_now) {
 			io_loop_get_wait_time(t, &tv, &ioloop_timeval);
@@ -348,7 +304,7 @@
 				  (void *) io->callback, io->fd);
 			io_remove(io);
 		}
-		io_destroy(ioloop, io);
+		io_destroy(ioloop, &ioloop->ios);
 	}
 
 	while (ioloop->timeouts != NULL) {
@@ -358,7 +314,7 @@
 			i_warning("Timeout leak: %p", (void *) to->callback);
 			timeout_remove(to);
 		}
-                timeout_destroy(ioloop, to);
+                timeout_destroy(ioloop, &ioloop->timeouts);
 	}
 
         io_loop_handler_deinit(ioloop);
--- a/src/lib/ioloop.h	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ioloop.h	Fri May 23 17:40:49 2003 +0300
@@ -7,10 +7,6 @@
 #define IO_READ			(1 << 0)
 #define IO_WRITE		(1 << 1)
 
-#define IO_PRIORITY_LOW		100
-#define IO_PRIORITY_DEFAULT	0
-#define IO_PRIORITY_HIGH	-100
-
 struct io;
 struct timeout;
 struct ioloop;
@@ -28,12 +24,10 @@
    but make sure you don't create multiple handlers of same type, it's not
    checked and removing one will stop the other from working as well. */
 struct io *io_add(int fd, int condition, io_callback_t *callback, void *context);
-struct io *io_add_priority(int fd, int priority, int condition,
-			   io_callback_t *callback, void *context);
 void io_remove(struct io *io);
 
 /* Timeout handlers */
-struct timeout *timeout_add(int msecs, timeout_callback_t *callback,
+struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback,
 			    void *context);
 void timeout_remove(struct timeout *timeout);
 
--- a/src/lib/ostream-file.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ostream-file.c	Fri May 23 17:40:49 2003 +0300
@@ -57,7 +57,6 @@
 	struct _ostream ostream;
 
 	int fd;
-	int priority;
 	struct io *io;
 
 	unsigned char *buffer; /* ring-buffer */
@@ -476,9 +475,8 @@
 
 	if (sent != 0 && fstream->io == NULL &&
 	    !fstream->corked && !fstream->file) {
-		fstream->io = io_add_priority(fstream->fd, fstream->priority,
-					      IO_WRITE, stream_send_io,
-					      fstream);
+		fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io,
+				     fstream);
 	}
 
 	i_assert(!STREAM_IS_BLOCKING(fstream) || sent == size);
@@ -840,7 +838,7 @@
 
 struct ostream *
 o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
-		     int priority, int autoclose_fd)
+		     int autoclose_fd)
 {
 	struct file_ostream *fstream;
 	struct ostream *ostream;
@@ -849,7 +847,6 @@
 
 	fstream = p_new(pool, struct file_ostream, 1);
 	fstream->fd = fd;
-	fstream->priority = priority;
 	fstream->max_buffer_size = max_buffer_size;
 	fstream->autoclose_fd = autoclose_fd;
 	fstream->optimal_block_size = DEFAULT_OPTIMAL_BLOCK_SIZE;
--- a/src/lib/ostream.h	Fri May 23 17:39:45 2003 +0300
+++ b/src/lib/ostream.h	Fri May 23 17:40:49 2003 +0300
@@ -12,7 +12,7 @@
 
 struct ostream *
 o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
-		     int priority, int autoclose_fd);
+		     int autoclose_fd);
 
 /* Reference counting. References start from 1, so calling o_stream_unref()
    destroys the stream if o_stream_ref() is never used. */
--- a/src/login-common/auth-connection.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/login-common/auth-connection.c	Fri May 23 17:40:49 2003 +0300
@@ -70,7 +70,7 @@
 	conn->input = i_stream_create_file(fd, default_pool, MAX_INBUF_SIZE,
 					   FALSE);
 	conn->output = o_stream_create_file(fd, default_pool, MAX_OUTBUF_SIZE,
-					    IO_PRIORITY_DEFAULT, FALSE);
+					    FALSE);
 	conn->requests = hash_create(default_pool, default_pool, 100,
 				     NULL, NULL);
 
--- a/src/master/auth-process.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/master/auth-process.c	Fri May 23 17:40:49 2003 +0300
@@ -207,7 +207,7 @@
 					MAX_INBUF_SIZE, FALSE);
 	p->output = o_stream_create_file(fd, default_pool,
 					 sizeof(struct auth_master_request)*100,
-					 IO_PRIORITY_DEFAULT, FALSE);
+					 FALSE);
 	p->requests = hash_create(default_pool, default_pool, 0, NULL, NULL);
 
 	p->next = group->processes;
--- a/src/master/login-process.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/master/login-process.c	Fri May 23 17:40:49 2003 +0300
@@ -312,7 +312,7 @@
 	p->io = io_add(fd, IO_READ, login_process_input, p);
 	p->output = o_stream_create_file(fd, default_pool,
 					 sizeof(struct master_login_reply)*10,
-					 IO_PRIORITY_DEFAULT, FALSE);
+					 FALSE);
 
 	PID_ADD_PROCESS_TYPE(pid, PROCESS_TYPE_LOGIN);
 	hash_insert(processes, POINTER_CAST(pid), p);
--- a/src/master/ssl-init-openssl.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/master/ssl-init-openssl.c	Fri May 23 17:40:49 2003 +0300
@@ -3,11 +3,156 @@
 #include "common.h"
 #include "ssl-init.h"
 
+#if 0
 #ifdef HAVE_OPENSSL
 
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+static int rsa_bits[] = { 512, 1024, 0 };
+static int dh_bits[] = { 768, 1024, 0 };
+
+static const char *ssl_last_error(void)
+{
+	unsigned long err;
+	char *buf;
+	size_t err_size = 256;
+
+	err = ERR_get_error();
+	if (err == 0)
+		return strerror(errno);
+
+	buf = t_malloc(err_size);
+	buf[err_size-1] = '\0';
+	ERR_error_string_n(err, buf, err_size-1);
+	return buf;
+}
+
+static void write_datum(int fd, const char *fname, gnutls_datum *dbits)
+{
+	if (write_full(fd, &dbits->size, sizeof(dbits->size)) < 0)
+		i_fatal("write_full() failed for file %s: %m", fname);
+
+	if (write_full(fd, dbits->data, dbits->size) < 0)
+		i_fatal("write_full() failed for file %s: %m", fname);
+}
+
+static void generate_dh_parameters(int fd, const char *fname)
+{
+	gnutls_datum dbits, prime, generator;
+	int ret, bits, i;
+
+	dbits.size = sizeof(bits);
+	dbits.data = (unsigned char *) &bits;
+
+	for (i = 0; dh_bits[i] != 0; i++) {
+		bits = dh_bits[i];
+
+		ret = gnutls_dh_params_generate(&prime, &generator, bits);
+		if (ret < 0) {
+			i_fatal("gnutls_dh_params_generate(%d) failed: %s",
+				bits, gnutls_strerror(ret));
+		}
+
+		write_datum(fd, fname, &dbits);
+		write_datum(fd, fname, &prime);
+		write_datum(fd, fname, &generator);
+
+		free(prime.data);
+		free(generator.data);
+	}
+
+	bits = 0;
+	write_datum(fd, fname, &dbits);
+}
+
+static void generate_rsa_parameters(int fd, const char *fname)
+{
+	RSA *rsa;
+	int ret;
+
+	for (i = 0; rsa_bits[i] != 0; i++) {
+		rsa = RSA_generate_key(rsa_bits[i], RSA_F4, NULL, NULL);
+		if (rsa == NULL) {
+			i_fatal("RSA_generate_keys(%d bits) failed: %s",
+				rsa_bits[i], ssl_last_error());
+		}
+
+
+
+		RSA_free(rsa);
+	}
+
+        ret = gnutls_rsa_params_generate(&m, &e, &d, &p, &q, &u, 512);
+	if (ret < 0) {
+		i_fatal("gnutls_rsa_params_generate() faile: %s",
+			strerror(ret));
+	}
+
+	write_datum(fd, fname, &m);
+	write_datum(fd, fname, &e);
+	write_datum(fd, fname, &d);
+	write_datum(fd, fname, &p);
+	write_datum(fd, fname, &q);
+	write_datum(fd, fname, &u);
+}
+
+void _ssl_generate_parameters(int fd, const char *fname)
+{
+	SSL_CTX *ssl_ctx;
+
+	SSL_library_init();
+	SSL_load_error_strings();
+
+	if ((ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
+		i_fatal("SSL_CTX_new() failed");
+
+	generate_dh_parameters(fd, fname);
+	generate_rsa_parameters(fd, fname);
+
+	SSL_CTX_free(ssl_ctx);
+}
+
+struct ssl_key_cache {
+	RSA *key;
+	int keylength;
+};
+
+static RSA *ssl_gen_rsa_key(SSL *ssl __attr_unused__,
+			    int is_export __attr_unused__, int keylength)
+{
+	static buffer_t *key_cache = NULL;
+	const struct ssl_key_cache *cache;
+	struct ssl_key_cache tmp_cache;
+	size_t i, size;
+
+	if (key_cache == NULL)
+		key_cache = buffer_create_dynamic(system_pool, 64, (size_t)-1);
+
+	cache = buffer_get_data(key_cache, &size);
+	size /= sizeof(struct ssl_key_cache);
+
+	for (i = 0; i < size; i++) {
+		if (cache[i].keylength == keylength)
+			return cache[i].key;
+	}
+
+	tmp_cache.key = RSA_generate_key(keylength, RSA_F4, NULL, NULL);
+	if (tmp_cache.key == NULL) {
+		i_error("Can't create temporary RSA key with length %d: %s",
+			keylength, ssl_last_error());
+		return NULL;
+	}
+	tmp_cache.keylength = keylength;
+	buffer_append(key_cache, &tmp_cache, sizeof(tmp_cache));
+
+	return tmp_cache.key;
+}
+
+#endif
+#else
 void _ssl_generate_parameters(int fd __attr_unused__,
 			      const char *fname __attr_unused__)
 {
 }
-
 #endif
--- a/src/pop3-login/client.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/pop3-login/client.c	Fri May 23 17:40:49 2003 +0300
@@ -53,8 +53,7 @@
 static void client_open_streams(struct pop3_client *client, int fd)
 {
 	client->input = i_stream_create_file(fd, default_pool, 8192, FALSE);
-	client->output = o_stream_create_file(fd, default_pool, 1024,
-					      IO_PRIORITY_DEFAULT, FALSE);
+	client->output = o_stream_create_file(fd, default_pool, 1024, FALSE);
 }
 
 static int cmd_stls(struct pop3_client *client)
--- a/src/pop3/client.c	Fri May 23 17:39:45 2003 +0300
+++ b/src/pop3/client.c	Fri May 23 17:40:49 2003 +0300
@@ -110,8 +110,7 @@
 	client = i_new(struct client, 1);
 	client->input = i_stream_create_file(hin, default_pool,
 					     MAX_INBUF_SIZE, FALSE);
-	client->output = o_stream_create_file(hout, default_pool, 4096,
-					      IO_PRIORITY_DEFAULT, FALSE);
+	client->output = o_stream_create_file(hout, default_pool, 4096, FALSE);
 
 	/* set timeout for sending data */
 	o_stream_set_blocking(client->output, CLIENT_OUTPUT_TIMEOUT,