]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Use the more efficient epoll update mechanism
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 15 Sep 2020 13:38:53 +0000 (15:38 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 10 Nov 2020 08:52:23 +0000 (09:52 +0100)
pdns/dnsdistdist/tcpiohandler-mplexer.hh

index e0e366dd78bc40c9fa699696b6d0cb2dd4f18f42..1971a3a1520cd9b434e66b6940ecb4be3c5bee57 100644 (file)
@@ -50,12 +50,12 @@ public:
   void update(IOState iostate, FDMultiplexer::callbackfunc_t callback = FDMultiplexer::callbackfunc_t(), FDMultiplexer::funcparam_t callbackData = boost::any(), boost::optional<struct timeval> ttd = boost::none)
   {
     DEBUGLOG("in "<<__PRETTY_FUNCTION__<<" for fd "<<d_fd<<", last state was "<<(int)d_currentState<<", new state is "<<(int)iostate);
-    if (d_currentState == IOState::NeedRead && iostate != IOState::NeedRead) {
+    if (d_currentState == IOState::NeedRead && iostate == IOState::Done) {
       DEBUGLOG(__PRETTY_FUNCTION__<<": remove read FD "<<d_fd);
       d_mplexer->removeReadFD(d_fd);
       d_currentState = IOState::Done;
     }
-    else if (d_currentState == IOState::NeedWrite && iostate != IOState::NeedWrite) {
+    else if (d_currentState == IOState::NeedWrite && iostate == IOState::Done) {
       DEBUGLOG(__PRETTY_FUNCTION__<<": remove write FD "<<d_fd);
       d_mplexer->removeWriteFD(d_fd);
       d_currentState = IOState::Done;
@@ -70,18 +70,33 @@ public:
         return;
       }
 
+      if (d_currentState == IOState::NeedWrite) {
+        d_mplexer->alterFDToRead(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+        DEBUGLOG(__PRETTY_FUNCTION__<<": alter from write to read FD "<<d_fd);
+      }
+      else {
+        d_mplexer->addReadFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+        DEBUGLOG(__PRETTY_FUNCTION__<<": add read FD "<<d_fd);
+      }
+
       d_currentState = IOState::NeedRead;
-      DEBUGLOG(__PRETTY_FUNCTION__<<": add read FD "<<d_fd);
-      d_mplexer->addReadFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+
     }
     else if (iostate == IOState::NeedWrite) {
       if (d_currentState == IOState::NeedWrite) {
         return;
       }
 
+      if (d_currentState == IOState::NeedRead) {
+        d_mplexer->alterFDToWrite(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+        DEBUGLOG(__PRETTY_FUNCTION__<<": alter from read to write FD "<<d_fd);
+      }
+      else {
+        d_mplexer->addWriteFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+        DEBUGLOG(__PRETTY_FUNCTION__<<": add write FD "<<d_fd);
+      }
+
       d_currentState = IOState::NeedWrite;
-      DEBUGLOG(__PRETTY_FUNCTION__<<": add write FD "<<d_fd);
-      d_mplexer->addWriteFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
     }
     else if (iostate == IOState::Done) {
       d_currentState = IOState::Done;