diff options
author | Vincent Richard <[email protected]> | 2014-01-05 12:53:44 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2014-01-05 12:53:44 +0000 |
commit | 8e5149448674088faf61aa9d8060f933c7520dc5 (patch) | |
tree | 38262e24a9496b086cc988096f7e526e208c77c7 /src | |
parent | Use block size of underlying stream. (diff) | |
download | vmime-8e5149448674088faf61aa9d8060f933c7520dc5.tar.gz vmime-8e5149448674088faf61aa9d8060f933c7520dc5.zip |
Report sending progress when chunking is supported.
Diffstat (limited to 'src')
-rw-r--r-- | src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp | 18 | ||||
-rw-r--r-- | src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp | 8 | ||||
-rw-r--r-- | src/vmime/net/smtp/SMTPTransport.cpp | 6 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp index 69f63bc9..5f59e381 100644 --- a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp +++ b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp @@ -40,9 +40,13 @@ namespace net { namespace smtp { -SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter(shared_ptr <SMTPConnection> conn) - : m_connection(conn), m_bufferSize(0), m_chunkCount(0) +SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter + (shared_ptr <SMTPConnection> conn, const size_t size, utility::progressListener* progress) + : m_connection(conn), m_bufferSize(0), m_chunkCount(0), + m_totalSize(size), m_totalSent(0), m_progress(progress) { + if (progress) + progress->start(size); } @@ -61,6 +65,14 @@ void SMTPChunkingOutputStreamAdapter::sendChunk ++m_chunkCount; + if (m_progress) + { + m_totalSent += count; + m_totalSize = std::max(m_totalSize, m_totalSent); + + m_progress->progress(m_totalSent, m_totalSize); + } + // If PIPELINING is not supported, read one response for this BDAT command if (!m_connection->hasExtension("PIPELINING")) { @@ -128,6 +140,8 @@ void SMTPChunkingOutputStreamAdapter::flush() { sendChunk(m_buffer, m_bufferSize, /* last */ true); m_bufferSize = 0; + + m_progress->stop(m_totalSize); } diff --git a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp index cfb3f50f..56d72fb1 100644 --- a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp +++ b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp @@ -32,6 +32,7 @@ #include "vmime/utility/outputStream.hpp" +#include "vmime/utility/progressListener.hpp" namespace vmime { @@ -48,7 +49,8 @@ class VMIME_EXPORT SMTPChunkingOutputStreamAdapter : public utility::outputStrea { public: - SMTPChunkingOutputStreamAdapter(shared_ptr <SMTPConnection> conn); + SMTPChunkingOutputStreamAdapter(shared_ptr <SMTPConnection> conn, + const size_t size, utility::progressListener* progress); void flush(); @@ -72,6 +74,10 @@ private: size_t m_bufferSize; unsigned int m_chunkCount; + + size_t m_totalSize; + size_t m_totalSent; + utility::progressListener* m_progress; }; diff --git a/src/vmime/net/smtp/SMTPTransport.cpp b/src/vmime/net/smtp/SMTPTransport.cpp index e2174dfb..56adfa21 100644 --- a/src/vmime/net/smtp/SMTPTransport.cpp +++ b/src/vmime/net/smtp/SMTPTransport.cpp @@ -369,11 +369,13 @@ void SMTPTransport::send } // Send message envelope + const size_t msgSize = msg->getGeneratedSize(ctx); + sendEnvelope(expeditor, recipients, sender, - /* sendDATACommand */ false, msg->getGeneratedSize(ctx)); + /* sendDATACommand */ false, msgSize); // Send the message by chunks - SMTPChunkingOutputStreamAdapter chunkStream(m_connection); + SMTPChunkingOutputStreamAdapter chunkStream(m_connection, msgSize, progress); msg->generate(ctx, chunkStream); |