From: Timo Sirainen Date: Tue, 23 Feb 2016 21:41:28 +0000 (+0200) Subject: lib: Added iostream_temp_create_sized() to specify the max in-memory size X-Git-Tag: 2.2.22.rc1~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a8a3b43987b5ade914f22765e51c9e3de8179d3;p=thirdparty%2Fdovecot%2Fcore.git lib: Added iostream_temp_create_sized() to specify the max in-memory size --- diff --git a/src/lib/iostream-temp.c b/src/lib/iostream-temp.c index 0d891d8039..134362c9f2 100644 --- a/src/lib/iostream-temp.c +++ b/src/lib/iostream-temp.c @@ -11,13 +11,14 @@ #include -#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; diff --git a/src/lib/iostream-temp.h b/src/lib/iostream-temp.h index b9dc624d86..8f16ff0e56 100644 --- a/src/lib/iostream-temp.h +++ b/src/lib/iostream-temp.h @@ -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);