]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login proxy: Use corking when writing data.
authorTimo Sirainen <tss@iki.fi>
Thu, 24 Oct 2013 13:08:23 +0000 (16:08 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 24 Oct 2013 13:08:23 +0000 (16:08 +0300)
src/login-common/client-common-auth.c
src/login-common/login-proxy.c

index 8a5d3cab6514a4a00a97d01781caf7950051f331..9400323d8de25c9e00bfd962032a884599903e5b 100644 (file)
@@ -222,6 +222,7 @@ static const char *get_disconnect_reason(struct istream *input)
 static void proxy_input(struct client *client)
 {
        struct istream *input;
+       struct ostream *output;
        const char *line;
        unsigned int duration;
 
@@ -265,10 +266,15 @@ static void proxy_input(struct client *client)
                return;
        }
 
+       output = client->output;
+       o_stream_ref(output);
+       o_stream_cork(output);
        while ((line = i_stream_next_line(input)) != NULL) {
                if (client->v.proxy_parse_line(client, line) != 0)
                        break;
        }
+       o_stream_uncork(output);
+       o_stream_unref(&output);
 }
 
 static int proxy_start(struct client *client,
index d2833e27845cb7d41064810c45e1b18dd6876bac..00a268fd5b001f70ffbebf6b8bb105a49eefef5b 100644 (file)
@@ -78,7 +78,7 @@ static void login_proxy_free_errno(struct login_proxy **proxy,
 static void server_input(struct login_proxy *proxy)
 {
        unsigned char buf[OUTBUF_THRESHOLD];
-       ssize_t ret;
+       ssize_t ret, ret2;
 
        proxy->last_io = ioloop_time;
        if (o_stream_get_buffer_used_size(proxy->client_output) >
@@ -90,9 +90,14 @@ static void server_input(struct login_proxy *proxy)
        }
 
        ret = net_receive(proxy->server_fd, buf, sizeof(buf));
-       if (ret < 0)
+       if (ret < 0) {
                login_proxy_free_errno(&proxy, errno, "server");
-       else if (o_stream_send(proxy->client_output, buf, ret) != ret) {
+               return;
+       }
+       o_stream_cork(proxy->client_output);
+       ret2 = o_stream_send(proxy->client_output, buf, ret);
+       o_stream_uncork(proxy->client_output);
+       if (ret2 != ret) {
                login_proxy_free_errno(&proxy,
                                       proxy->client_output->stream_errno,
                                       "client");
@@ -102,7 +107,7 @@ static void server_input(struct login_proxy *proxy)
 static void proxy_client_input(struct login_proxy *proxy)
 {
        unsigned char buf[OUTBUF_THRESHOLD];
-       ssize_t ret;
+       ssize_t ret, ret2;
 
        proxy->last_io = ioloop_time;
        if (o_stream_get_buffer_used_size(proxy->server_output) >
@@ -114,9 +119,14 @@ static void proxy_client_input(struct login_proxy *proxy)
        }
 
        ret = net_receive(proxy->client_fd, buf, sizeof(buf));
-       if (ret < 0)
+       if (ret < 0) {
                login_proxy_free_errno(&proxy, errno, "client");
-       else if (o_stream_send(proxy->server_output, buf, ret) != ret) {
+               return;
+       }
+       o_stream_cork(proxy->client_output);
+       ret2 = o_stream_send(proxy->server_output, buf, ret);
+       o_stream_uncork(proxy->server_output);
+       if (ret2 != ret) {
                login_proxy_free_errno(&proxy,
                                       proxy->server_output->stream_errno,
                                       "server");