From: Timo Sirainen Date: Fri, 13 Nov 2009 21:55:03 +0000 (-0500) Subject: dsync: Avoid hanging. X-Git-Tag: 2.0.beta1~155 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee2bc185924586dbebb62db37753b8439712acce;p=thirdparty%2Fdovecot%2Fcore.git dsync: Avoid hanging. --HG-- branch : HEAD --- diff --git a/src/dsync/dsync-proxy-server-cmd.c b/src/dsync/dsync-proxy-server-cmd.c index fef95d9566..4032bc8cbc 100644 --- a/src/dsync/dsync-proxy-server-cmd.c +++ b/src/dsync/dsync-proxy-server-cmd.c @@ -9,6 +9,7 @@ #include "istream-dot.h" #include "ostream.h" #include "imap-util.h" +#include "master-service.h" #include "dsync-worker.h" #include "dsync-proxy.h" #include "dsync-proxy-server.h" diff --git a/src/dsync/dsync-proxy-server.c b/src/dsync/dsync-proxy-server.c index fedb7d266a..5e3eb334ec 100644 --- a/src/dsync/dsync-proxy-server.c +++ b/src/dsync/dsync-proxy-server.c @@ -103,6 +103,8 @@ static void proxy_server_input(struct dsync_proxy_server *server) break; } o_stream_uncork(server->output); + if (server->output->closed) + ret = -1; if (ret < 0) master_service_stop(master_service); @@ -114,20 +116,23 @@ static int proxy_server_output(struct dsync_proxy_server *server) int ret; if ((ret = o_stream_flush(output)) < 0) - return 1; - - if (server->cur_cmd != NULL) { + ret = 1; + else if (server->cur_cmd != NULL) { o_stream_cork(output); (void)proxy_server_run_cmd(server); o_stream_uncork(output); - if (server->cur_cmd == NULL && server->io == NULL) { - server->io = io_add(server->fd_in, IO_READ, - proxy_server_input, server); + if (server->cur_cmd == NULL) { + if (server->io == NULL) { + server->io = io_add(server->fd_in, IO_READ, + proxy_server_input, server); + } /* handle pending input */ proxy_server_input(server); } } + if (output->closed) + master_service_stop(master_service); return ret; } diff --git a/src/dsync/test-dsync-proxy-server-cmd.c b/src/dsync/test-dsync-proxy-server-cmd.c index e213c03507..7379f4e355 100644 --- a/src/dsync/test-dsync-proxy-server-cmd.c +++ b/src/dsync/test-dsync-proxy-server-cmd.c @@ -6,6 +6,7 @@ #include "strescape.h" #include "istream.h" #include "ostream.h" +#include "master-service.h" #include "test-common.h" #include "dsync-proxy-server.h" #include "test-dsync-worker.h" @@ -13,12 +14,15 @@ #define ALL_MAIL_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft \\Recent" +struct master_service *master_service; static string_t *out; static struct dsync_proxy_server *server; static struct test_dsync_worker *test_worker; static struct dsync_proxy_server_command *cur_cmd; static const char *cur_cmd_args[20]; +void master_service_stop(struct master_service *service ATTR_UNUSED) {} + static void out_clear(void) { o_stream_seek(server->output, 0);