]> granicus.if.org Git - icinga2/commitdiff
Prevent unnecessary thread wake-ups
authorGunnar Beutner <gunnar@beutner.name>
Tue, 24 Feb 2015 07:31:14 +0000 (08:31 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 24 Feb 2015 07:41:06 +0000 (08:41 +0100)
refs #8485

lib/base/tlsstream.cpp

index f55cd9c1291eb4c2c40583a81dff5ae73496fc53..829da6f08381b2fcd16f794dab5b42f685de79d9 100644 (file)
@@ -128,10 +128,14 @@ void TlsStream::OnEvent(int revents)
        char buffer[512];
 
        if (m_CurrentAction == TlsActionNone) {
-               if (m_SendQ->GetAvailableBytes() > 0 && (revents & POLLOUT))
-                       m_CurrentAction = TlsActionWrite;
-               else
+               if (revents & POLLIN)
                        m_CurrentAction = TlsActionRead;
+               else if (m_SendQ->GetAvailableBytes() > 0 && (revents & POLLOUT))
+                       m_CurrentAction = TlsActionWrite;
+               else {
+                       ChangeEvents(POLLIN);
+                       return;
+               }
        }
 
        switch (m_CurrentAction) {
@@ -177,13 +181,12 @@ void TlsStream::OnEvent(int revents)
        }
 
        if (rc > 0) {
-               if (m_SendQ->GetAvailableBytes() > 0) {
-                       m_CurrentAction = TlsActionWrite;
+               m_CurrentAction = TlsActionNone;
+
+               if (m_SendQ->GetAvailableBytes() > 0)
                        ChangeEvents(POLLIN|POLLOUT);
-               } else {
-                       m_CurrentAction = TlsActionNone;
+               else
                        ChangeEvents(POLLIN);
-               }
 
                lock.unlock();
 
@@ -205,7 +208,7 @@ void TlsStream::OnEvent(int revents)
                        break;
                case SSL_ERROR_WANT_WRITE:
                        m_Retry = true;
-                       ChangeEvents(POLLIN|POLLOUT);
+                       ChangeEvents(POLLOUT);
 
                        break;
                case SSL_ERROR_ZERO_RETURN: