dovecot-2.2: lib: Added o_stream_flush_parent_if_needed() for wr...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jul 3 18:57:10 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/5740cb57d02c
changeset: 17590:5740cb57d02c
user: Timo Sirainen <tss at iki.fi>
date: Thu Jul 03 21:54:52 2014 +0300
description:
lib: Added o_stream_flush_parent_if_needed() for wrapper ostreams.
diffstat:
src/lib/ostream-private.h | 4 ++++
src/lib/ostream.c | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diffs (40 lines):
diff -r 5f21c78cd7b2 -r 5740cb57d02c src/lib/ostream-private.h
--- a/src/lib/ostream-private.h Thu Jul 03 20:42:08 2014 +0300
+++ b/src/lib/ostream-private.h Thu Jul 03 21:54:52 2014 +0300
@@ -50,5 +50,9 @@
size_t block_size);
void o_stream_copy_error_from_parent(struct ostream_private *_stream);
+/* This should be called before sending data to parent stream. It makes sure
+ that the parent stream's output buffer doesn't become too large.
+ Returns 1 if more data can be safely added, 0 if not, -1 if error. */
+int o_stream_flush_parent_if_needed(struct ostream_private *_stream);
#endif
diff -r 5f21c78cd7b2 -r 5740cb57d02c src/lib/ostream.c
--- a/src/lib/ostream.c Thu Jul 03 20:42:08 2014 +0300
+++ b/src/lib/ostream.c Thu Jul 03 21:54:52 2014 +0300
@@ -451,6 +451,23 @@
o_stream_close(dest);
}
+int o_stream_flush_parent_if_needed(struct ostream_private *_stream)
+{
+ if (o_stream_get_buffer_used_size(_stream->parent) >= IO_BLOCK_SIZE) {
+ /* we already have quite a lot of data in parent stream.
+ unless we can flush it, don't add any more to it or we
+ could keep wasting memory by just increasing the buffer
+ size all the time. */
+ if (o_stream_flush(_stream->parent) < 0) {
+ o_stream_copy_error_from_parent(_stream);
+ return -1;
+ }
+ if (o_stream_get_buffer_used_size(_stream->parent) >= IO_BLOCK_SIZE)
+ return 0;
+ }
+ return 1;
+}
+
static int o_stream_default_flush(struct ostream_private *_stream)
{
int ret;
More information about the dovecot-cvs
mailing list