diff options
| author | Vincent Richard <[email protected]> | 2009-11-30 14:04:15 +0100 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2009-11-30 14:04:15 +0100 |
| commit | 5d8282568759f1e7c33537153f1ac0f190d64888 (patch) | |
| tree | 14ac69ed9aa177668c4366f7d3c7fe4f58af32b7 /src | |
| parent | Quote mailbox name instead of encoding it whenever it's possible. (diff) | |
| download | vmime-5d8282568759f1e7c33537153f1ac0f190d64888.tar.gz vmime-5d8282568759f1e7c33537153f1ac0f190d64888.zip | |
Added block size on sockets to allow different buffer size for SSL.
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/imap/IMAPConnection.cpp | 6 | ||||
| -rw-r--r-- | src/net/imap/IMAPFolder.cpp | 6 | ||||
| -rw-r--r-- | src/net/tls/TLSSocket.cpp | 10 | ||||
| -rw-r--r-- | src/platforms/posix/posixSocket.cpp | 12 | ||||
| -rw-r--r-- | src/platforms/windows/windowsSocket.cpp | 10 | ||||
| -rw-r--r-- | src/security/sasl/SASLSocket.cpp | 10 | ||||
| -rw-r--r-- | src/utility/stream.cpp | 4 |
7 files changed, 46 insertions, 12 deletions
diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp index c3ee5740..6e5a265c 100644 --- a/src/net/imap/IMAPConnection.cpp +++ b/src/net/imap/IMAPConnection.cpp @@ -718,6 +718,12 @@ ref <session> IMAPConnection::getSession() } +ref <const socket> IMAPConnection::getSocket() const +{ + return m_socket; +} + + } // imap } // net } // vmime diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp index c06a8d43..0122d217 100644 --- a/src/net/imap/IMAPFolder.cpp +++ b/src/net/imap/IMAPFolder.cpp @@ -1284,7 +1284,11 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int if (progress) progress->start(total); - char buffer[65536]; + const socket::size_type blockSize = std::min(is.getBlockSize(), + static_cast <size_t>(m_connection->getSocket()->getBlockSize())); + + std::vector <char> vbuffer(blockSize); + char* buffer = &vbuffer.front(); while (!is.eof()) { diff --git a/src/net/tls/TLSSocket.cpp b/src/net/tls/TLSSocket.cpp index c2f91f62..dab0338c 100644 --- a/src/net/tls/TLSSocket.cpp +++ b/src/net/tls/TLSSocket.cpp @@ -90,6 +90,12 @@ bool TLSSocket::isConnected() const } +TLSSocket::size_type TLSSocket::getBlockSize() const +{ + return 16384; // 16 KB +} + + void TLSSocket::receive(string& buffer) { const int size = receiveRaw(m_buffer, sizeof(m_buffer)); @@ -103,7 +109,7 @@ void TLSSocket::send(const string& buffer) } -int TLSSocket::receiveRaw(char* buffer, const int count) +TLSSocket::size_type TLSSocket::receiveRaw(char* buffer, const size_type count) { const ssize_t ret = gnutls_record_recv (*m_session->m_gnutlsSession, @@ -124,7 +130,7 @@ int TLSSocket::receiveRaw(char* buffer, const int count) } -void TLSSocket::sendRaw(const char* buffer, const int count) +void TLSSocket::sendRaw(const char* buffer, const size_type count) { gnutls_record_send (*m_session->m_gnutlsSession, diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp index 67409955..807ec47c 100644 --- a/src/platforms/posix/posixSocket.cpp +++ b/src/platforms/posix/posixSocket.cpp @@ -217,6 +217,12 @@ void posixSocket::disconnect() } +posixSocket::size_type posixSocket::getBlockSize() const +{ + return 16384; // 16 KB +} + + void posixSocket::receive(vmime::string& buffer) { const int size = receiveRaw(m_buffer, sizeof(m_buffer)); @@ -224,7 +230,7 @@ void posixSocket::receive(vmime::string& buffer) } -int posixSocket::receiveRaw(char* buffer, const int count) +posixSocket::size_type posixSocket::receiveRaw(char* buffer, const size_type count) { const int ret = ::recv(m_desc, buffer, count, 0); @@ -252,9 +258,9 @@ void posixSocket::send(const vmime::string& buffer) } -void posixSocket::sendRaw(const char* buffer, const int count) +void posixSocket::sendRaw(const char* buffer, const size_type count) { - int size = count; + size_type size = count; while (size > 0) { diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index 8a425836..3ff9ad50 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -121,6 +121,12 @@ void windowsSocket::disconnect() } +windowsSocket::size_type windowsSocket::getBlockSize() const +{ + return 16384; // 16 KB +} + + void windowsSocket::receive(vmime::string& buffer) { int ret = ::recv(m_desc, m_buffer, sizeof(m_buffer), 0); @@ -137,7 +143,7 @@ void windowsSocket::receive(vmime::string& buffer) } -int windowsSocket::receiveRaw(char* buffer, const int count) +windowsSocket::size_type windowsSocket::receiveRaw(char* buffer, const size_type count) { int ret = ::recv(m_desc, buffer, count, 0); @@ -159,7 +165,7 @@ void windowsSocket::send(const vmime::string& buffer) } -void windowsSocket::sendRaw(const char* buffer, const int count) +void windowsSocket::sendRaw(const char* buffer, const size_type count) { ::send(m_desc, buffer, count, 0); } diff --git a/src/security/sasl/SASLSocket.cpp b/src/security/sasl/SASLSocket.cpp index 118429ab..d88153e4 100644 --- a/src/security/sasl/SASLSocket.cpp +++ b/src/security/sasl/SASLSocket.cpp @@ -69,6 +69,12 @@ bool SASLSocket::isConnected() const } +SASLSocket::size_type SASLSocket::getBlockSize() const +{ + return m_wrapped->getBlockSize(); +} + + void SASLSocket::receive(string& buffer) { const int n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); @@ -77,7 +83,7 @@ void SASLSocket::receive(string& buffer) } -int SASLSocket::receiveRaw(char* buffer, const int count) +SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count) { if (m_pendingLen != 0) { @@ -141,7 +147,7 @@ void SASLSocket::send(const string& buffer) } -void SASLSocket::sendRaw(const char* buffer, const int count) +void SASLSocket::sendRaw(const char* buffer, const size_type count) { byte_t* output = 0; int outputLen = 0; diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp index 483784ce..ec30b7d3 100644 --- a/src/utility/stream.cpp +++ b/src/utility/stream.cpp @@ -470,7 +470,7 @@ void outputStreamSocketAdapter::flush() stream::size_type outputStreamSocketAdapter::getBlockSize() { - return 16384; // 16 KB + return m_socket.getBlockSize(); } @@ -513,7 +513,7 @@ stream::size_type inputStreamSocketAdapter::skip stream::size_type inputStreamSocketAdapter::getBlockSize() { - return 16384; // 16 KB + return m_socket.getBlockSize(); } |
