]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Added 15 min connection timeout.
authorTimo Sirainen <tss@iki.fi>
Mon, 16 Nov 2009 18:37:22 +0000 (13:37 -0500)
committerTimo Sirainen <tss@iki.fi>
Mon, 16 Nov 2009 18:37:22 +0000 (13:37 -0500)
--HG--
branch : HEAD

src/dsync/dsync-proxy-client.c
src/dsync/dsync-proxy-server.c
src/dsync/dsync-proxy-server.h
src/dsync/dsync-proxy.h

index 60dfa42ab3b0f184602e022d025ccf9c5c741655..692069d7f8f1ffa9be474e7b3484892016a9684a 100644 (file)
@@ -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(struct proxy_client_dsync_worker *worker)
        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(struct proxy_client_dsync_worker *worker)
 {
        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(struct proxy_client_dsync_worker *worker)
        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_proxy_client(int fd_in, int fd_out)
        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(struct dsync_worker *_worker)
        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);
index 5e3eb334ec5b0aa0f1f325cc145cf386276a2a3a..e82817206726bdb543c7727cae954280efd47326 100644 (file)
@@ -94,6 +94,7 @@ static void proxy_server_input(struct dsync_proxy_server *server)
                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 dsync_proxy_server *server)
        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 dsync_proxy_server *server)
        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 fd_out, struct dsync_worker *worker)
        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 dsync_proxy_server **_server)
        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);
index 217eaa7874056879530fbba544ca6019dbe74cce..4958a7c0a6f2b98ae0234ca9a879c362882ba25b 100644 (file)
@@ -14,6 +14,7 @@ struct dsync_proxy_server {
        struct io *io;
        struct istream *input;
        struct ostream *output;
+       struct timeout *to;
 
        struct dsync_worker *worker;
 
index a367c79aa56f213436dc6afc11e56e75f3d51a48..40c68bba8a71d8cd65ff120583bd2501d92d41ab 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "dsync-data.h"
 
+#define DSYNC_PROXY_TIMEOUT_MSECS (15*60*1000)
+
 struct dsync_message;
 struct dsync_mailbox;