Preferred block size for streams.
This commit is contained in:
parent
c31f38f108
commit
afc1548ac4
@ -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
|
||||
|
||||
|
||||
|
@ -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&);
|
||||
|
Loading…
Reference in New Issue
Block a user