]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added i_stream_set_persistent_buffers()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 10 Feb 2016 20:02:15 +0000 (22:02 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 11 Feb 2016 11:35:01 +0000 (13:35 +0200)
src/lib/istream-private.h
src/lib/istream.c
src/lib/istream.h

index 54a91d83af3647abe30a9b3eadad4a366312d5c6..c6b69d5754134683f5848d986af47cd9f955f6e3 100644 (file)
@@ -52,6 +52,7 @@ struct istream_private {
        unsigned int line_crlf:1;
        unsigned int return_nolf_line:1;
        unsigned int stream_size_passthrough:1; /* stream is parent's size */
+       unsigned int nonpersistent_buffers:1;
 };
 
 struct istream * ATTR_NOWARN_UNUSED_RESULT
index 4f2988936b0d168d306e0a60c8b094a0b9308940..2d70a230db798a1477501590c888913f48474dbd 100644 (file)
@@ -122,6 +122,14 @@ void i_stream_set_return_partial_line(struct istream *stream, bool set)
        stream->real_stream->return_nolf_line = set;
 }
 
+void i_stream_set_persistent_buffers(struct istream *stream, bool set)
+{
+       do {
+               stream->real_stream->nonpersistent_buffers = !set;
+               stream = stream->real_stream->parent;
+       } while (stream != NULL);
+}
+
 static void i_stream_update(struct istream_private *stream)
 {
        if (stream->parent == NULL)
@@ -238,6 +246,12 @@ void i_stream_skip(struct istream *stream, uoff_t count)
                /* within buffer */
                stream->v_offset += count;
                _stream->skip += count;
+               if (_stream->nonpersistent_buffers &&
+                   _stream->skip == _stream->pos) {
+                       _stream->skip = _stream->pos = 0;
+                       _stream->buffer_size = 0;
+                       i_free_and_null(_stream->w_buffer);
+               }
                return;
        }
 
index d47d36bdb95a140eac4b88c54719bf3af7cb496f..0c96e9896719a0b48f9bbd8f865c58e55a615dba 100644 (file)
@@ -97,6 +97,10 @@ size_t i_stream_get_max_buffer_size(struct istream *stream);
 /* Enable/disable i_stream[_read]_next_line() returning the last line if it
    doesn't end with LF. */
 void i_stream_set_return_partial_line(struct istream *stream, bool set);
+/* Change whether buffers are allocated persistently (default=TRUE). When not,
+   the memory usage is minimized by freeing the stream's buffers whenever they
+   become empty. */
+void i_stream_set_persistent_buffers(struct istream *stream, bool set);
 
 /* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
    input buffer is full. */