diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-02-28 17:21:49 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-02-28 17:21:49 +0100 |
commit | b8d0753b0b10fd9307e5cc7b9a8b463e0b339c67 (patch) | |
tree | 2a0c6b214fa537d6d65208ed78164316ad37559b /src/modules/extra | |
parent | 7c158dd9778ff81d92558cdfbe0e978d1edca84c (diff) |
m_ssl_gnutls Move logic that reads data from a session into new class GnuTLS::DataReader
Diffstat (limited to 'src/modules/extra')
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 65e550267..667ad5681 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -451,6 +451,28 @@ namespace GnuTLS } }; + class DataReader + { + int retval; + char* const buffer; + + public: + DataReader(gnutls_session_t sess) + : buffer(ServerInstance->GetReadBuffer()) + { + // Read data from GnuTLS buffers into ReadBuffer + retval = gnutls_record_recv(sess, buffer, ServerInstance->Config->NetBufferSize); + } + + void appendto(std::string& recvq) + { + // Copy data from ReadBuffer to recvq + recvq.append(buffer, retval); + } + + int ret() const { return retval; } + }; + class Profile : public refcountbase { /** Name of this profile @@ -848,12 +870,11 @@ info_done_dealloc: if (this->status == ISSL_HANDSHAKEN) { - char* buffer = ServerInstance->GetReadBuffer(); - size_t bufsiz = ServerInstance->Config->NetBufferSize; - int ret = gnutls_record_recv(this->sess, buffer, bufsiz); + GnuTLS::DataReader reader(sess); + int ret = reader.ret(); if (ret > 0) { - recvq.append(buffer, ret); + reader.appendto(recvq); return 1; } else if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) |