dovecot-2.0-sslstream: dsync: Added 15 min connection timeout.

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:56:25 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/2e4fc44c6160
changeset: 10331:2e4fc44c6160
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 16 13:37:22 2009 -0500
description:
dsync: Added 15 min connection timeout.

diffstat:

4 files changed, 26 insertions(+)
src/dsync/dsync-proxy-client.c |   12 ++++++++++++
src/dsync/dsync-proxy-server.c |   11 +++++++++++
src/dsync/dsync-proxy-server.h |    1 +
src/dsync/dsync-proxy.h        |    2 ++

diffs (129 lines):

diff -r 32a754b2d79b -r 2e4fc44c6160 src/dsync/dsync-proxy-client.c
--- a/src/dsync/dsync-proxy-client.c	Mon Nov 16 11:35:52 2009 -0500
+++ b/src/dsync/dsync-proxy-client.c	Mon Nov 16 13:37:22 2009 -0500
@@ -51,6 +51,7 @@ struct proxy_client_dsync_worker {
 	struct io *io;
 	struct istream *input;
 	struct ostream *output;
+	struct timeout *to;
 
 	mailbox_guid_t selected_box_guid;
 
@@ -226,6 +227,7 @@ static void proxy_client_worker_input(st
 	const char *line;
 	int ret;
 
+	timeout_reset(worker->to);
 	if (worker->worker.input_callback != NULL) {
 		worker->worker.input_callback(worker->worker.input_context);
 		return;
@@ -245,6 +247,7 @@ static int proxy_client_worker_output(st
 {
 	int ret;
 
+	timeout_reset(worker->to);
 	if ((ret = o_stream_flush(worker->output)) < 0)
 		return 1;
 
@@ -261,6 +264,12 @@ static int proxy_client_worker_output(st
 	return ret;
 }
 
+static void proxy_client_worker_timeout(void *context ATTR_UNUSED)
+{
+	i_error("proxy client timed out");
+	master_service_stop(master_service);
+}
+
 struct dsync_worker *dsync_worker_init_proxy_client(int fd_in, int fd_out)
 {
 	struct proxy_client_dsync_worker *worker;
@@ -269,6 +278,8 @@ struct dsync_worker *dsync_worker_init_p
 	worker->worker.v = proxy_client_dsync_worker;
 	worker->fd_in = fd_in;
 	worker->fd_out = fd_out;
+	worker->to = timeout_add(DSYNC_PROXY_TIMEOUT_MSECS,
+				 proxy_client_worker_timeout, NULL);
 	worker->io = io_add(fd_in, IO_READ, proxy_client_worker_input, worker);
 	worker->input = i_stream_create_fd(fd_in, (size_t)-1, FALSE);
 	worker->output = o_stream_create_fd(fd_out, (size_t)-1, FALSE);
@@ -291,6 +302,7 @@ static void proxy_client_worker_deinit(s
 	struct proxy_client_dsync_worker *worker =
 		(struct proxy_client_dsync_worker *)_worker;
 
+	timeout_remove(&worker->to);
 	if (worker->io != NULL)
 		io_remove(&worker->io);
 	i_stream_destroy(&worker->input);
diff -r 32a754b2d79b -r 2e4fc44c6160 src/dsync/dsync-proxy-server.c
--- a/src/dsync/dsync-proxy-server.c	Mon Nov 16 11:35:52 2009 -0500
+++ b/src/dsync/dsync-proxy-server.c	Mon Nov 16 13:37:22 2009 -0500
@@ -94,6 +94,7 @@ static void proxy_server_input(struct ds
 		return;
 	}
 
+	timeout_reset(server->to);
 	o_stream_cork(server->output);
 	while (proxy_server_read_line(server, &line) > 0) {
 		T_BEGIN {
@@ -115,6 +116,7 @@ static int proxy_server_output(struct ds
 	struct ostream *output = server->output;
 	int ret;
 
+	timeout_reset(server->to);
 	if ((ret = o_stream_flush(output)) < 0)
 		ret = 1;
 	else if (server->cur_cmd != NULL) {
@@ -136,6 +138,12 @@ static int proxy_server_output(struct ds
 	return ret;
 }
 
+static void dsync_proxy_server_timeout(void *context ATTR_UNUSED)
+{
+	i_error("proxy server timed out");
+	master_service_stop(master_service);
+}
+
 struct dsync_proxy_server *
 dsync_proxy_server_init(int fd_in, int fd_out, struct dsync_worker *worker)
 {
@@ -150,6 +158,8 @@ dsync_proxy_server_init(int fd_in, int f
 	server->io = io_add(fd_in, IO_READ, proxy_server_input, server);
 	server->input = i_stream_create_fd(fd_in, (size_t)-1, FALSE);
 	server->output = o_stream_create_fd(fd_out, (size_t)-1, FALSE);
+	server->to = timeout_add(DSYNC_PROXY_TIMEOUT_MSECS,
+				 dsync_proxy_server_timeout, NULL);
 	o_stream_set_flush_callback(server->output, proxy_server_output,
 				    server);
 	fd_set_nonblock(fd_in, TRUE);
@@ -166,6 +176,7 @@ void dsync_proxy_server_deinit(struct ds
 	if (server->get_input != NULL)
 		i_stream_unref(&server->get_input);
 	pool_unref(&server->cmd_pool);
+	timeout_remove(&server->to);
 	io_remove(&server->io);
 	i_stream_destroy(&server->input);
 	o_stream_destroy(&server->output);
diff -r 32a754b2d79b -r 2e4fc44c6160 src/dsync/dsync-proxy-server.h
--- a/src/dsync/dsync-proxy-server.h	Mon Nov 16 11:35:52 2009 -0500
+++ b/src/dsync/dsync-proxy-server.h	Mon Nov 16 13:37:22 2009 -0500
@@ -14,6 +14,7 @@ struct dsync_proxy_server {
 	struct io *io;
 	struct istream *input;
 	struct ostream *output;
+	struct timeout *to;
 
 	struct dsync_worker *worker;
 
diff -r 32a754b2d79b -r 2e4fc44c6160 src/dsync/dsync-proxy.h
--- a/src/dsync/dsync-proxy.h	Mon Nov 16 11:35:52 2009 -0500
+++ b/src/dsync/dsync-proxy.h	Mon Nov 16 13:37:22 2009 -0500
@@ -2,6 +2,8 @@
 #define DSYNC_PROXY_H
 
 #include "dsync-data.h"
+
+#define DSYNC_PROXY_TIMEOUT_MSECS (15*60*1000)
 
 struct dsync_message;
 struct dsync_mailbox;


More information about the dovecot-cvs mailing list