Preferred block size for streams.

This commit is contained in:
Vincent Richard 2006-11-18 09:27:30 +00:00
parent c31f38f108
commit afc1548ac4
2 changed files with 38 additions and 1 deletions

View File

@ -32,6 +32,14 @@ namespace vmime {
namespace utility { namespace utility {
// stream
const stream::size_type stream::getBlockSize() const
{
return 32768; // 32 KB
}
// Helpers // Helpers
outputStream& operator<<(outputStream& os, const stream::value_type c) 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 bufferedStreamCopy(inputStream& is, outputStream& os,
const stream::size_type length, progressListener* progress) 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; stream::size_type total = 0;
if (progress != NULL) if (progress != NULL)
@ -443,6 +456,13 @@ void outputStreamSocketAdapter::flush()
} }
const stream::size_type outputStreamSocketAdapter::getBlockSize() const
{
return 16384; // 16 KB
}
// inputStreamSocketAdapter // inputStreamSocketAdapter
inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok) 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 #endif // VMIME_HAVE_MESSAGING_FEATURES

View File

@ -71,6 +71,13 @@ public:
/** Type used for lengths in streams. /** Type used for lengths in streams.
*/ */
typedef string::size_type size_type; 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 write(const value_type* const data, const size_type count);
void flush(); void flush();
const size_type getBlockSize() const;
private: private:
outputStreamSocketAdapter(const outputStreamSocketAdapter&); outputStreamSocketAdapter(const outputStreamSocketAdapter&);
@ -417,6 +426,8 @@ public:
const size_type read(value_type* const data, const size_type count); const size_type read(value_type* const data, const size_type count);
const size_type skip(const size_type count); const size_type skip(const size_type count);
const size_type getBlockSize() const;
private: private:
inputStreamSocketAdapter(const inputStreamSocketAdapter&); inputStreamSocketAdapter(const inputStreamSocketAdapter&);