Write all responses before reading requests 06/319506/1
authorKrzysztof Malysa <k.malysa@samsung.com>
Thu, 24 Oct 2024 10:31:11 +0000 (12:31 +0200)
committerKrzysztof Malysa <k.malysa@samsung.com>
Thu, 24 Oct 2024 10:36:37 +0000 (12:36 +0200)
Change-Id: Ibf7d8e9b11c1a02c0dbf9c2ef95a1c6be9be5a5e

src/service/sockets/SocketManager.cpp

index a3ed7e660f0580a49bcfbb71ff90d1fd30982b7e..b69cc91d8e4d6c129ccb3d707034625fe65dea04 100644 (file)
@@ -188,15 +188,24 @@ void SocketManager::mainLoop(void) {
                 throw UnexpectedErrorException(err, safeStrError(err));
             }
         } else if (ret > 0) {
+            // First, write responses
+            int readyForReadNum = 0;
             for (int i = 0; i < m_maxDesc + 1 && ret; ++i) {
-                if (FD_ISSET(i, &readSet)) {
-                    readyForRead(i);
-                    --ret;
-                }
                 if (FD_ISSET(i, &writeSet)) {
                     readyForWrite(i);
                     --ret;
                 }
+                if (FD_ISSET(i, &readSet)) {
+                    --ret;
+                    ++readyForReadNum;
+                }
+            }
+            // Then accept new connections and requests
+            for (int i = 0; i < m_maxDesc + 1 && readyForReadNum; ++i) {
+                if (FD_ISSET(i, &readSet)) {
+                    readyForRead(i);
+                    --readyForReadNum;
+                }
             }
 
             LOGD("checking sockets <= %i for data to write", m_maxDesc);