Added block size on sockets to allow different buffer size for SSL.

This commit is contained in:
Vincent Richard 2009-11-30 13:04:15 +00:00
parent 90f838232f
commit 5d82825687
13 changed files with 78 additions and 22 deletions

View File

@ -718,6 +718,12 @@ ref <session> IMAPConnection::getSession()
} }
ref <const socket> IMAPConnection::getSocket() const
{
return m_socket;
}
} // imap } // imap
} // net } // net
} // vmime } // vmime

View File

@ -1284,7 +1284,11 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
if (progress) if (progress)
progress->start(total); 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()) while (!is.eof())
{ {

View File

@ -90,6 +90,12 @@ bool TLSSocket::isConnected() const
} }
TLSSocket::size_type TLSSocket::getBlockSize() const
{
return 16384; // 16 KB
}
void TLSSocket::receive(string& buffer) void TLSSocket::receive(string& buffer)
{ {
const int size = receiveRaw(m_buffer, sizeof(m_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 const ssize_t ret = gnutls_record_recv
(*m_session->m_gnutlsSession, (*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 gnutls_record_send
(*m_session->m_gnutlsSession, (*m_session->m_gnutlsSession,

View File

@ -217,6 +217,12 @@ void posixSocket::disconnect()
} }
posixSocket::size_type posixSocket::getBlockSize() const
{
return 16384; // 16 KB
}
void posixSocket::receive(vmime::string& buffer) void posixSocket::receive(vmime::string& buffer)
{ {
const int size = receiveRaw(m_buffer, sizeof(m_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); 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) while (size > 0)
{ {

View File

@ -121,6 +121,12 @@ void windowsSocket::disconnect()
} }
windowsSocket::size_type windowsSocket::getBlockSize() const
{
return 16384; // 16 KB
}
void windowsSocket::receive(vmime::string& buffer) void windowsSocket::receive(vmime::string& buffer)
{ {
int ret = ::recv(m_desc, m_buffer, sizeof(m_buffer), 0); 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); 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); ::send(m_desc, buffer, count, 0);
} }

View File

@ -69,6 +69,12 @@ bool SASLSocket::isConnected() const
} }
SASLSocket::size_type SASLSocket::getBlockSize() const
{
return m_wrapped->getBlockSize();
}
void SASLSocket::receive(string& buffer) void SASLSocket::receive(string& buffer)
{ {
const int n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); 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) 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; byte_t* output = 0;
int outputLen = 0; int outputLen = 0;

View File

@ -470,7 +470,7 @@ void outputStreamSocketAdapter::flush()
stream::size_type outputStreamSocketAdapter::getBlockSize() 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() stream::size_type inputStreamSocketAdapter::getBlockSize()
{ {
return 16384; // 16 KB return m_socket.getBlockSize();
} }

View File

@ -96,6 +96,8 @@ public:
bool isSecuredConnection() const; bool isSecuredConnection() const;
ref <connectionInfos> getConnectionInfos() const; ref <connectionInfos> getConnectionInfos() const;
ref <const socket> getSocket() const;
private: private:
void authenticate(); void authenticate();

View File

@ -41,6 +41,11 @@ public:
virtual ~socket() { } virtual ~socket() { }
/** Type used for lengths in streams.
*/
typedef int size_type;
/** Connect to the specified address and port. /** Connect to the specified address and port.
* *
* @param address server address (this can be a full qualified domain name * @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) * @param count maximum number of bytes to receive (size of buffer)
* @return number of bytes received/written into output 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. /** Send (text) data to the socket.
* *
@ -84,7 +89,14 @@ public:
* @param buffer data to send * @param buffer data to send
* @param count number of bytes to send (size of buffer) * @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: protected:

View File

@ -84,10 +84,12 @@ public:
bool isConnected() const; bool isConnected() const;
void receive(string& buffer); 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 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: private:

View File

@ -48,10 +48,12 @@ public:
void disconnect(); void disconnect();
void receive(vmime::string& buffer); 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 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: protected:

View File

@ -50,10 +50,12 @@ public:
void disconnect(); void disconnect();
void receive(vmime::string& buffer); 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 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: private:

View File

@ -53,10 +53,12 @@ public:
bool isConnected() const; bool isConnected() const;
void receive(string& buffer); 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 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: private: