diff options
-rw-r--r-- | include/socketengine.h | 5 | ||||
-rw-r--r-- | src/inspsocket.cpp | 6 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 12 | ||||
-rw-r--r-- | src/socketengine.cpp | 14 |
4 files changed, 34 insertions, 3 deletions
diff --git a/include/socketengine.h b/include/socketengine.h index b790f6d77..293d27e43 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -489,6 +489,11 @@ public: /** Get data transfer statistics, kilobits per second in and out and total. */ void GetStats(float &kbitpersec_in, float &kbitpersec_out, float &kbitpersec_total); + + /** Should we ignore the error in errno? + * Checks EAGAIN and WSAEWOULDBLOCK + */ + static bool IgnoreError(); }; SocketEngine* CreateSocketEngine(); diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 27c6f87ec..d78ace318 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -200,7 +200,7 @@ void StreamSocket::DoRead() error = "Connection closed"; ServerInstance->SE->ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); } - else if (errno == EAGAIN) + else if (SocketEngine::IgnoreError()) { ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK); } @@ -291,7 +291,7 @@ void StreamSocket::DoWrite() } else if (rv < 0) { - if (errno == EAGAIN || errno == EINTR) + if (errno == EINTR || SocketEngine::IgnoreError()) ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); else SetError(strerror(errno)); @@ -388,7 +388,7 @@ void StreamSocket::DoWrite() { error = "Connection closed"; } - else if (errno == EAGAIN) + else if (SocketEngine::IgnoreError()) { eventChange = FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK; } diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 38b3700b5..e329186a5 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -86,6 +86,12 @@ static ssize_t gnutls_pull_wrapper(gnutls_transport_ptr_t user_wrap, void* buffe return -1; } int rv = ServerInstance->SE->Recv(user, reinterpret_cast<char *>(buffer), size, 0); + if (rv < 0) + { + /* On Windows we need to set errno for gnutls */ + if (SocketEngine::IgnoreError()) + errno = EAGAIN; + } if (rv < (int)size) ServerInstance->SE->ChangeEventMask(user, FD_READ_WILL_BLOCK); return rv; @@ -100,6 +106,12 @@ static ssize_t gnutls_push_wrapper(gnutls_transport_ptr_t user_wrap, const void* return -1; } int rv = ServerInstance->SE->Send(user, reinterpret_cast<const char *>(buffer), size, 0); + if (rv < 0) + { + /* On Windows we need to set errno for gnutls */ + if (SocketEngine::IgnoreError()) + errno = EAGAIN; + } if (rv < (int)size) ServerInstance->SE->ChangeEventMask(user, FD_WRITE_WILL_BLOCK); return rv; diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 6c99edc95..cbdfb5651 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -255,3 +255,17 @@ void SocketEngine::GetStats(float &kbitpersec_in, float &kbitpersec_out, float & kbitpersec_in = in_kbit / 1024; kbitpersec_out = out_kbit / 1024; } + +bool SocketEngine::IgnoreError() +{ + if (errno == EAGAIN) + return true; + +#ifdef _WIN32 + if (WSAGetLastError() == WSAEWOULDBLOCK) + return true; +#endif + + return false; +} + |