diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:42:42 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:42:42 +0000 |
commit | da1010f4077eae5d1602c9fe7d74a2426387b8b2 (patch) | |
tree | da81a4643afaf8e638e7dd3f4ee0f9efed10ffc4 /src | |
parent | 9a09770a5433c3867e8cb2014a48e9624c82fccf (diff) |
Read multiple GnuTLS records in one RawSocketRead operation
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11589 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index b2b59e612..f05a73227 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -520,34 +520,43 @@ class ModuleSSLGnuTLS : public Module if (session->status == ISSL_HANDSHAKEN) { - int ret = gnutls_record_recv(session->sess, buffer, count); - - if (ret > 0) + unsigned int len = 0; + while (len < count) { - readresult = ret; + int ret = gnutls_record_recv(session->sess, buffer + len, count - len); + if (ret > 0) + { + len += ret; + } + else if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) + { + break; + } + else + { + if (ret != 0) + ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, + "m_ssl_gnutls.so: Error while reading on fd %d: %s", + fd, gnutls_strerror(ret)); + + // if ret == 0, client closed connection. + readresult = 0; + CloseSession(session); + return 1; + } } - else if (ret == 0) + readresult = len; + if (len) { - // Client closed connection. - readresult = 0; - CloseSession(session); return 1; } - else if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) + else { errno = EAGAIN; return -1; } - else - { - ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, - "m_ssl_gnutls.so: Error while reading on fd %d: %s", - fd, gnutls_strerror(ret)); - readresult = 0; - CloseSession(session); - } } - else if(session->status == ISSL_CLOSING) + else if (session->status == ISSL_CLOSING) readresult = 0; return 1; @@ -610,7 +619,8 @@ class ModuleSSLGnuTLS : public Module } } - MakePollWrite(fd); + if (!session->outbuf.empty()) + MakePollWrite(fd); /* Who's smart idea was it to return 1 when we havent written anything? * This fucks the buffer up in BufferedSocket :p |