summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-02-28 17:29:30 +0100
committerAttila Molnar <attilamolnar@hush.com>2015-02-28 17:29:30 +0100
commit2d42e4828a5d4afa484c5b6089e5bfd9ebd760cf (patch)
tree661cf5275c7c8ba33091a9a4d1bf4dcf6d07945e /src/modules
parentb8d0753b0b10fd9307e5cc7b9a8b463e0b339c67 (diff)
m_ssl_gnutls Implement faster reads on GnuTLS 3.3.5 and later by avoiding copying the data from GnuTLS buffers to ReadBuffer
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 667ad5681..ad182e826 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -79,6 +79,10 @@ typedef gnutls_retr2_st cert_cb_last_param_type;
typedef gnutls_retr_st cert_cb_last_param_type;
#endif
+#if INSPIRCD_GNUTLS_HAS_VERSION(3, 3, 5)
+#define INSPIRCD_GNUTLS_HAS_RECV_PACKET
+#endif
+
class RandGen : public HandlerBase2<void, char*, size_t>
{
public:
@@ -454,6 +458,28 @@ namespace GnuTLS
class DataReader
{
int retval;
+#ifdef INSPIRCD_GNUTLS_HAS_RECV_PACKET
+ gnutls_packet_t packet;
+
+ public:
+ DataReader(gnutls_session_t sess)
+ {
+ // Using the packet API avoids the final copy of the data which GnuTLS does if we supply
+ // our own buffer. Instead, we get the buffer containing the data from GnuTLS and copy it
+ // to the recvq directly from there in appendto().
+ retval = gnutls_record_recv_packet(sess, &packet);
+ }
+
+ void appendto(std::string& recvq)
+ {
+ // Copy data from GnuTLS buffers to recvq
+ gnutls_datum_t datum;
+ gnutls_packet_get(packet, &datum, NULL);
+ recvq.append(reinterpret_cast<const char*>(datum.data), datum.size);
+
+ gnutls_packet_deinit(packet);
+ }
+#else
char* const buffer;
public:
@@ -469,6 +495,7 @@ namespace GnuTLS
// Copy data from ReadBuffer to recvq
recvq.append(buffer, retval);
}
+#endif
int ret() const { return retval; }
};