Mercurial > dovecot > core-2.2
changeset 10708:3b544841d5d7 HEAD
ostream: If cork method isn't implemented, keep track of corking state internally.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 14 Feb 2010 21:49:13 +0200 |
parents | 72a345621cd2 |
children | 52e1f46fe0ba |
files | src/lib/ostream-file.c src/lib/ostream-internal.h src/lib/ostream.c |
diffstat | 3 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/ostream-file.c Sat Feb 13 13:49:31 2010 +0200 +++ b/src/lib/ostream-file.c Sun Feb 14 21:49:13 2010 +0200 @@ -42,7 +42,6 @@ unsigned int full:1; /* if head == tail, is buffer empty or full? */ unsigned int file:1; - unsigned int corked:1; unsigned int flush_pending:1; unsigned int socket_cork_set:1; unsigned int no_socket_cork:1; @@ -132,7 +131,7 @@ static void o_stream_socket_cork(struct file_ostream *fstream) { - if (fstream->corked && !fstream->socket_cork_set) { + if (fstream->ostream.corked && !fstream->socket_cork_set) { if (!fstream->no_socket_cork) { if (net_set_cork(fstream->fd, TRUE) < 0) fstream->no_socket_cork = TRUE; @@ -324,7 +323,7 @@ struct file_ostream *fstream = (struct file_ostream *)stream; int ret; - if (fstream->corked != set && !stream->ostream.closed) { + if (stream->corked != set && !stream->ostream.closed) { if (set && fstream->io != NULL) io_remove(&fstream->io); else if (!set) { @@ -344,7 +343,7 @@ fstream->no_socket_cork = TRUE; fstream->socket_cork_set = FALSE; } - fstream->corked = set; + stream->corked = set; } } @@ -361,7 +360,7 @@ struct file_ostream *fstream = (struct file_ostream *) stream; fstream->flush_pending = set; - if (set && !fstream->corked && fstream->io == NULL) { + if (set && !stream->corked && fstream->io == NULL) { fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io, fstream); } @@ -414,7 +413,7 @@ if (size > fstream->ostream.max_buffer_size) { /* limit the size */ size = fstream->ostream.max_buffer_size; - } else if (fstream->corked) { + } else if (fstream->ostream.corked) { /* try to use optimal buffer size with corking */ new_size = I_MIN(fstream->optimal_block_size, fstream->ostream.max_buffer_size); @@ -509,7 +508,7 @@ } if (sent != 0 && fstream->io == NULL && - !fstream->corked && !fstream->file) { + !fstream->ostream.corked && !fstream->file) { fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io, fstream); } @@ -538,7 +537,7 @@ optimal_size = I_MIN(fstream->optimal_block_size, fstream->ostream.max_buffer_size); if (IS_STREAM_EMPTY(fstream) && - (!fstream->corked || size >= optimal_size)) { + (!stream->corked || size >= optimal_size)) { /* send immediately */ ret = o_stream_writev(fstream, iov, iov_count); if (ret < 0)
--- a/src/lib/ostream-internal.h Sat Feb 13 13:49:31 2010 +0200 +++ b/src/lib/ostream-internal.h Sun Feb 14 21:49:13 2010 +0200 @@ -28,6 +28,8 @@ stream_flush_callback_t *callback; void *context; + + unsigned int corked:1; }; struct ostream *o_stream_create(struct ostream_private *_stream);
--- a/src/lib/ostream.c Sat Feb 13 13:49:31 2010 +0200 +++ b/src/lib/ostream.c Sun Feb 14 21:49:13 2010 +0200 @@ -65,6 +65,8 @@ if (_stream->cork != NULL) _stream->cork(_stream, TRUE); + else + _stream->corked = TRUE; } void o_stream_uncork(struct ostream *stream) @@ -76,8 +78,10 @@ if (_stream->cork != NULL) _stream->cork(_stream, FALSE); - else + else { + _stream->corked = FALSE; (void)o_stream_flush(stream); + } } int o_stream_flush(struct ostream *stream)