From: Timo Sirainen Date: Sun, 29 Oct 2017 21:28:38 +0000 (+0200) Subject: lib: iostream-pump - Cork the ostream when writing X-Git-Tag: 2.3.0.rc1~663 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84b746f56209d4a85af73cd26850e75f519ae0b0;p=thirdparty%2Fdovecot%2Fcore.git lib: iostream-pump - Cork the ostream when writing This reduces latency for TCP connections by disabling Nagle algorithm. --- diff --git a/src/lib/iostream-pump.c b/src/lib/iostream-pump.c index 1d3901187d..b725af958d 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -28,12 +28,14 @@ void iostream_pump_copy(struct iostream_pump *pump) { enum ostream_send_istream_result res; + o_stream_cork(pump->output); size_t old_size = o_stream_get_max_buffer_size(pump->output); o_stream_set_max_buffer_size(pump->output, I_MIN(IO_BLOCK_SIZE, o_stream_get_max_buffer_size(pump->output))); res = o_stream_send_istream(pump->output, pump->input); o_stream_set_max_buffer_size(pump->output, old_size); + o_stream_uncork(pump->output); switch(res) { case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT: diff --git a/src/lib/test-iostream-pump.c b/src/lib/test-iostream-pump.c index 95135c20a4..8650c3dd24 100644 --- a/src/lib/test-iostream-pump.c +++ b/src/lib/test-iostream-pump.c @@ -105,6 +105,8 @@ const char *run_pump(struct istream *in, struct ostream *out, int *counter, buff /* input failed, finish flushing output */ test_ostream_set_max_output_size(ctx.out, (size_t)-1); test_assert(o_stream_flush(ctx.out) > 0); + } else { + test_assert(o_stream_flush(ctx.out) != 0); } const char *ret = t_strdup(str_c(out_buffer));