]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added iostream_temp_create_sized() to specify the max in-memory size
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 23 Feb 2016 21:41:28 +0000 (23:41 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 23 Feb 2016 21:41:28 +0000 (23:41 +0200)
src/lib/iostream-temp.c
src/lib/iostream-temp.h

index 0d891d80390ff8d360e19435ca5f28bce7f0755d..134362c9f2071c59440a49e556106c5231953b2e 100644 (file)
 
 #include <unistd.h>
 
-#define IOSTREAM_TEMP_MAX_BUF_SIZE (1024*128)
+#define IOSTREAM_TEMP_MAX_BUF_SIZE_DEFAULT (1024*128)
 
 struct temp_ostream {
        struct ostream_private ostream;
 
        char *temp_path_prefix;
        enum iostream_temp_flags flags;
+       size_t max_mem_size;
 
        struct istream *dupstream;
        uoff_t dupstream_offset, dupstream_start_offset;
@@ -105,7 +106,7 @@ o_stream_temp_sendv(struct ostream_private *stream,
                return o_stream_temp_fd_sendv(tstream, iov, iov_count);
 
        for (i = 0; i < iov_count; i++) {
-               if (tstream->buf->used + iov[i].iov_len > IOSTREAM_TEMP_MAX_BUF_SIZE) {
+               if (tstream->buf->used + iov[i].iov_len > tstream->max_mem_size) {
                        if (o_stream_temp_move_to_fd(tstream) == 0) {
                                return o_stream_temp_fd_sendv(tstream, iov+i,
                                                              iov_count-i);
@@ -221,6 +222,15 @@ struct ostream *iostream_temp_create(const char *temp_path_prefix,
 struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
                                           enum iostream_temp_flags flags,
                                           const char *name)
+{
+       return iostream_temp_create_sized(temp_path_prefix, flags, name,
+                                         IOSTREAM_TEMP_MAX_BUF_SIZE_DEFAULT);
+}
+
+struct ostream *iostream_temp_create_sized(const char *temp_path_prefix,
+                                          enum iostream_temp_flags flags,
+                                          const char *name,
+                                          size_t max_mem_size)
 {
        struct temp_ostream *tstream;
        struct ostream *output;
@@ -232,6 +242,7 @@ struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
        tstream->ostream.iostream.close = o_stream_temp_close;
        tstream->temp_path_prefix = i_strdup(temp_path_prefix);
        tstream->flags = flags;
+       tstream->max_mem_size = max_mem_size;
        tstream->buf = buffer_create_dynamic(default_pool, 8192);
        tstream->fd = -1;
 
index b9dc624d86417fc9def4d3e888dade092c764caf..8f16ff0e56ae544201d0824d72db2db6d4ee4c96 100644 (file)
@@ -15,8 +15,13 @@ struct ostream *iostream_temp_create(const char *temp_path_prefix,
 struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
                                           enum iostream_temp_flags flags,
                                           const char *name);
+struct ostream *iostream_temp_create_sized(const char *temp_path_prefix,
+                                          enum iostream_temp_flags flags,
+                                          const char *name,
+                                          size_t max_mem_size);
 /* Finished writing to stream. Return input stream for it and free the
-   output stream. */
+   output stream. (It's also possible to abort iostream-temp by simply
+   destroying the ostream.) */
 struct istream *iostream_temp_finish(struct ostream **output,
                                     size_t max_buffer_size);