aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utility/stream.cpp28
-rw-r--r--vmime/utility/stream.hpp11
2 files changed, 38 insertions, 1 deletions
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index f2a89a55..48869958 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -32,6 +32,14 @@ namespace vmime {
namespace utility {
+// stream
+
+const stream::size_type stream::getBlockSize() const
+{
+ return 32768; // 32 KB
+}
+
+
// Helpers
outputStream& operator<<(outputStream& os, const stream::value_type c)
@@ -57,7 +65,12 @@ const stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
const stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
const stream::size_type length, progressListener* progress)
{
- stream::value_type buffer[16384];
+ const stream::size_type blockSize =
+ std::min(is.getBlockSize(), os.getBlockSize());
+
+ std::vector <stream::value_type> vbuffer(blockSize);
+
+ stream::value_type* buffer = &vbuffer.front();
stream::size_type total = 0;
if (progress != NULL)
@@ -443,6 +456,13 @@ void outputStreamSocketAdapter::flush()
}
+const stream::size_type outputStreamSocketAdapter::getBlockSize() const
+{
+ return 16384; // 16 KB
+}
+
+
+
// inputStreamSocketAdapter
inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
@@ -479,6 +499,12 @@ const stream::size_type inputStreamSocketAdapter::skip
}
+const stream::size_type inputStreamSocketAdapter::getBlockSize() const
+{
+ return 16384; // 16 KB
+}
+
+
#endif // VMIME_HAVE_MESSAGING_FEATURES
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index 87c1c7fe..b8d0d189 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -71,6 +71,13 @@ public:
/** Type used for lengths in streams.
*/
typedef string::size_type size_type;
+
+ /** Return the preferred maximum block size when reading
+ * from or writing to this stream.
+ *
+ * @return block size, in bytes
+ */
+ virtual const size_type getBlockSize() const;
};
@@ -395,6 +402,8 @@ public:
void write(const value_type* const data, const size_type count);
void flush();
+ const size_type getBlockSize() const;
+
private:
outputStreamSocketAdapter(const outputStreamSocketAdapter&);
@@ -417,6 +426,8 @@ public:
const size_type read(value_type* const data, const size_type count);
const size_type skip(const size_type count);
+ const size_type getBlockSize() const;
+
private:
inputStreamSocketAdapter(const inputStreamSocketAdapter&);