aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/net/imap/IMAPConnection.cpp6
-rw-r--r--src/net/imap/IMAPFolder.cpp6
-rw-r--r--src/net/tls/TLSSocket.cpp10
-rw-r--r--src/platforms/posix/posixSocket.cpp12
-rw-r--r--src/platforms/windows/windowsSocket.cpp10
-rw-r--r--src/security/sasl/SASLSocket.cpp10
-rw-r--r--src/utility/stream.cpp4
-rw-r--r--vmime/net/imap/IMAPConnection.hpp2
-rw-r--r--vmime/net/socket.hpp16
-rw-r--r--vmime/net/tls/TLSSocket.hpp6
-rw-r--r--vmime/platforms/posix/posixSocket.hpp6
-rw-r--r--vmime/platforms/windows/windowsSocket.hpp6
-rw-r--r--vmime/security/sasl/SASLSocket.hpp6
13 files changed, 78 insertions, 22 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();
}
diff --git a/vmime/net/imap/IMAPConnection.hpp b/vmime/net/imap/IMAPConnection.hpp
index 147c4df9..820987b3 100644
--- a/vmime/net/imap/IMAPConnection.hpp
+++ b/vmime/net/imap/IMAPConnection.hpp
@@ -96,6 +96,8 @@ public:
bool isSecuredConnection() const;
ref <connectionInfos> getConnectionInfos() const;
+ ref <const socket> getSocket() const;
+
private:
void authenticate();
diff --git a/vmime/net/socket.hpp b/vmime/net/socket.hpp
index 9b0319cc..ec6a9d37 100644
--- a/vmime/net/socket.hpp
+++ b/vmime/net/socket.hpp
@@ -41,6 +41,11 @@ public:
virtual ~socket() { }
+ /** Type used for lengths in streams.
+ */
+ typedef int size_type;
+
+
/** Connect to the specified address and port.
*
* @param address server address (this can be a full qualified domain name
@@ -71,7 +76,7 @@ public:
* @param count maximum number of bytes to receive (size of buffer)
* @return number of bytes received/written into output buffer
*/
- virtual int receiveRaw(char* buffer, const int count) = 0;
+ virtual int receiveRaw(char* buffer, const size_type count) = 0;
/** Send (text) data to the socket.
*
@@ -84,7 +89,14 @@ public:
* @param buffer data to send
* @param count number of bytes to send (size of buffer)
*/
- virtual void sendRaw(const char* buffer, const int count) = 0;
+ virtual void sendRaw(const char* buffer, const size_type count) = 0;
+
+ /** Return the preferred maximum block size when reading
+ * from or writing to this stream.
+ *
+ * @return block size, in bytes
+ */
+ virtual size_type getBlockSize() const = 0;
protected:
diff --git a/vmime/net/tls/TLSSocket.hpp b/vmime/net/tls/TLSSocket.hpp
index 5112550b..7c389702 100644
--- a/vmime/net/tls/TLSSocket.hpp
+++ b/vmime/net/tls/TLSSocket.hpp
@@ -84,10 +84,12 @@ public:
bool isConnected() const;
void receive(string& buffer);
- int receiveRaw(char* buffer, const int count);
+ size_type receiveRaw(char* buffer, const size_type count);
void send(const string& buffer);
- void sendRaw(const char* buffer, const int count);
+ void sendRaw(const char* buffer, const size_type count);
+
+ size_type getBlockSize() const;
private:
diff --git a/vmime/platforms/posix/posixSocket.hpp b/vmime/platforms/posix/posixSocket.hpp
index 0d0dae6a..9cd49d4a 100644
--- a/vmime/platforms/posix/posixSocket.hpp
+++ b/vmime/platforms/posix/posixSocket.hpp
@@ -48,10 +48,12 @@ public:
void disconnect();
void receive(vmime::string& buffer);
- int receiveRaw(char* buffer, const int count);
+ size_type receiveRaw(char* buffer, const size_type count);
void send(const vmime::string& buffer);
- void sendRaw(const char* buffer, const int count);
+ void sendRaw(const char* buffer, const size_type count);
+
+ size_type getBlockSize() const;
protected:
diff --git a/vmime/platforms/windows/windowsSocket.hpp b/vmime/platforms/windows/windowsSocket.hpp
index 61475c3f..2940157b 100644
--- a/vmime/platforms/windows/windowsSocket.hpp
+++ b/vmime/platforms/windows/windowsSocket.hpp
@@ -50,10 +50,12 @@ public:
void disconnect();
void receive(vmime::string& buffer);
- int receiveRaw(char* buffer, const int count);
+ size_type receiveRaw(char* buffer, const size_type count);
void send(const vmime::string& buffer);
- void sendRaw(const char* buffer, const int count);
+ void sendRaw(const char* buffer, const size_type count);
+
+ size_type getBlockSize() const;
private:
diff --git a/vmime/security/sasl/SASLSocket.hpp b/vmime/security/sasl/SASLSocket.hpp
index 3ff27e3e..03483315 100644
--- a/vmime/security/sasl/SASLSocket.hpp
+++ b/vmime/security/sasl/SASLSocket.hpp
@@ -53,10 +53,12 @@ public:
bool isConnected() const;
void receive(string& buffer);
- int receiveRaw(char* buffer, const int count);
+ size_type receiveRaw(char* buffer, const size_type count);
void send(const string& buffer);
- void sendRaw(const char* buffer, const int count);
+ void sendRaw(const char* buffer, const size_type count);
+
+ size_type getBlockSize() const;
private: