diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-08-09 00:39:48 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-08-09 00:45:42 +0300 |
commit | 93970a7554512add3e9192a8eeabd0abbedcc5c0 (patch) | |
tree | acd4ab01a038dd293d86512a3ab8b4c316ae8acd /include | |
parent | fd9a86d37b96789d59e25e64b5d9db8974158a2c (diff) | |
download | mailutils-93970a7554512add3e9192a8eeabd0abbedcc5c0.tar.gz mailutils-93970a7554512add3e9192a8eeabd0abbedcc5c0.tar.bz2 |
Implement temporary streams.
A temporary stream functions as a memory stream until its size reaches
a preconfigured threshold value. Once it is reached, the stream storage
is automatically converted to a temporary file, and all data written so far
are transferred to the new storage. If the temporary file cannot be
created, the stream continues to operate in memory-based mode.
This stream type is intended to decrease the number of used file
descriptors.
* include/mailutils/sys/Makefile.am: Add temp_stream.h
* include/mailutils/sys/temp_stream.h: New file.
* include/mailutils/stream.h (mu_temp_file_threshold_size): New extern.
(mu_temp_stream_create): New proto.
* libmailutils/stream/Makefile.am: Add temp_stream.c.
* libmailutils/stream/temp_stream.c: New file.
* libmailutils/string/Makefile.am: Add strtosize.c
* libmailutils/tests/.gitignore: Update.
* libmailutils/tests/Makefile.am
* libmailutils/tests/strtoc.c: Add tests for mu_c_hsize.
* libmailutils/tests/temp_stream.c: New test program.
* libmailutils/tests/testsuite.at: Test the temp_stream functionality.
* testsuite/testsuite.inc (MU_CHECK): New macro.
* libmailutils/mailbox/body.c (body_get_transport): Use mu_temp_stream_create.
Diffstat (limited to 'include')
-rw-r--r-- | include/mailutils/stream.h | 5 | ||||
-rw-r--r-- | include/mailutils/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/mailutils/sys/temp_stream.h | 35 |
3 files changed, 40 insertions, 1 deletions
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h index a91f168de..dc3bb12ad 100644 --- a/include/mailutils/stream.h +++ b/include/mailutils/stream.h @@ -474,7 +474,10 @@ int mu_nullstream_create (mu_stream_t *pref, int flags); int mu_wordwrap_stream_create (mu_stream_t *pstream, mu_stream_t transport, size_t left_margin, size_t right_margin); - + +extern size_t mu_temp_file_threshold_size; +int mu_temp_stream_create (mu_stream_t *pstream, size_t threshold); + #ifdef __cplusplus } #endif diff --git a/include/mailutils/sys/Makefile.am b/include/mailutils/sys/Makefile.am index 31225ef81..435792aa0 100644 --- a/include/mailutils/sys/Makefile.am +++ b/include/mailutils/sys/Makefile.am @@ -59,6 +59,7 @@ sysinclude_HEADERS = \ stream.h\ syslogstream.h\ temp_file_stream.h\ + temp_stream.h\ tls-stream.h\ url.h\ xscript-stream.h\ diff --git a/include/mailutils/sys/temp_stream.h b/include/mailutils/sys/temp_stream.h new file mode 100644 index 000000000..9061aef7e --- /dev/null +++ b/include/mailutils/sys/temp_stream.h @@ -0,0 +1,35 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2020 Free Software Foundation, Inc. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef _MAILUTILS_SYS_TEMP_STREAM_H +#define _MAILUTILS_SYS_TEMP_STREAM_H + +#include <mailutils/sys/stream.h> +#include <mailutils/sys/memory_stream.h> +#include <mailutils/sys/temp_file_stream.h> + +struct _mu_temp_stream +{ + union + { + struct _mu_stream stream; + struct _mu_memory_stream mem; + struct _mu_temp_file_stream file; + } s; + size_t max_size; + int (*saved_write) (struct _mu_stream *, const char *, size_t, size_t *); +}; +#endif |