From a2708e745c0e2cb78072102d8b59b0620b150dc0 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 26 Feb 2014 19:10:40 +0100 Subject: [PATCH] Fixed possible issues with EAGAIN on Windows. --- src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp | 25 ++++++++++--------- src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp | 3 +++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp index 3832326c..33e25261 100644 --- a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp +++ b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp @@ -59,12 +59,13 @@ shared_ptr TLSSocket::wrap(shared_ptr session, shared_p TLSSocket_GnuTLS::TLSSocket_GnuTLS(shared_ptr session, shared_ptr sok) : m_session(session), m_wrapped(sok), m_connected(false), - m_ex(NULL), m_status(0) + m_ex(NULL), m_status(0), m_errno(0) { gnutls_transport_set_ptr(*m_session->m_gnutlsSession, this); gnutls_transport_set_push_function(*m_session->m_gnutlsSession, gnutlsPushFunc); gnutls_transport_set_pull_function(*m_session->m_gnutlsSession, gnutlsPullFunc); + gnutls_transport_set_errno_function(*m_session->m_gnutlsSession, gnutlsErrnoFunc); } @@ -308,7 +309,6 @@ void TLSSocket_GnuTLS::handshake() else if (ret == GNUTLS_E_INTERRUPTED) { // Non-fatal error - m_wrapped->waitForRead(); } else { @@ -339,6 +339,13 @@ void TLSSocket_GnuTLS::handshake() } +int TLSSocket_GnuTLS::gnutlsErrnoFunc(gnutls_transport_ptr trspt) +{ + TLSSocket_GnuTLS* sok = reinterpret_cast (trspt); + return sok->m_errno; +} + + ssize_t TLSSocket_GnuTLS::gnutlsPushFunc (gnutls_transport_ptr trspt, const void* data, size_t len) { @@ -352,11 +359,8 @@ ssize_t TLSSocket_GnuTLS::gnutlsPushFunc if (ret == 0) { - if (sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) - gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, EAGAIN); - else - gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, 0); - + gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, EAGAIN); + sok->m_errno = EAGAIN; return -1; } @@ -385,11 +389,8 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc if (n == 0) { - if (sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) - gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, EAGAIN); - else - gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, 0); - + gnutls_transport_set_errno(*sok->m_session->m_gnutlsSession, EAGAIN); + sok->m_errno = EAGAIN; return -1; } diff --git a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp index faa3a423..5c819caf 100644 --- a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp +++ b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp @@ -90,9 +90,11 @@ private: #ifdef LIBGNUTLS_VERSION static ssize_t gnutlsPushFunc(gnutls_transport_ptr trspt, const void* data, size_t len); static ssize_t gnutlsPullFunc(gnutls_transport_ptr trspt, void* data, size_t len); + static int gnutlsErrnoFunc(gnutls_transport_ptr trspt); #else static int gnutlsPushFunc(void* trspt, const void* data, size_t len); static int gnutlsPullFunc(void* trspt, void* data, size_t len); + static int gnutlsErrnoFunc(void* trspt); #endif // LIBGNUTLS_VERSION @@ -106,6 +108,7 @@ private: exception* m_ex; unsigned int m_status; + int m_errno; };