From b8d0753b0b10fd9307e5cc7b9a8b463e0b339c67 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 28 Feb 2015 17:21:49 +0100 Subject: m_ssl_gnutls Move logic that reads data from a session into new class GnuTLS::DataReader --- src/modules/extra/m_ssl_gnutls.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/modules') 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) -- cgit v1.2.3