]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
mplexer: Add support for write timeouts
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 8 Mar 2019 15:41:22 +0000 (16:41 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 4 Apr 2019 09:46:26 +0000 (11:46 +0200)
pdns/mplexer.hh

index c28a1f218b1c152af1ffedbe6dc7be90076941c7..7de3a8a459ff0440bb18a0661b2f9c1d2b4cd801 100644 (file)
@@ -83,9 +83,9 @@ public:
   }
 
   //! Add an fd to the write watch list - currently an fd can only be on one list at a time!
-  virtual void addWriteFD(int fd, callbackfunc_t toDo, const funcparam_t& parameter=funcparam_t())
+  virtual void addWriteFD(int fd, callbackfunc_t toDo, const funcparam_t& parameter=funcparam_t(), const struct timeval* ttd=nullptr)
   {
-    this->addFD(d_writeCallbacks, fd, toDo, parameter);
+    this->addFD(d_writeCallbacks, fd, toDo, parameter, ttd);
   }
 
   //! Remove an fd from the read watch list. You can't call this function on an fd that is closed already!
@@ -113,6 +113,17 @@ public:
     it->second.d_ttd = tv;
   }
 
+  virtual void setWriteTTD(int fd, struct timeval tv, int timeout)
+  {
+    const auto& it = d_writeCallbacks.find(fd);
+    if (it == d_writeCallbacks.end()) {
+      throw FDMultiplexerException("attempt to timestamp fd not in the multiplexer");
+    }
+
+    tv.tv_sec += timeout;
+    it->second.d_ttd = tv;
+  }
+
   virtual funcparam_t& getReadParameter(int fd) 
   {
     const auto& it = d_readCallbacks.find(fd);
@@ -123,12 +134,12 @@ public:
     return it->second.d_parameter;
   }
 
-  virtual std::vector<std::pair<int, funcparam_t> > getTimeouts(const struct timeval& tv)
+  virtual std::vector<std::pair<int, funcparam_t> > getTimeouts(const struct timeval& tv, bool writes=false)
   {
     const auto tied = boost::tie(tv.tv_sec, tv.tv_usec);
     std::vector<std::pair<int, funcparam_t> > ret;
 
-    for(const auto& entry : d_readCallbacks) {
+    for(const auto& entry : (writes ? d_writeCallbacks : d_readCallbacks)) {
       if(entry.second.d_ttd.tv_sec && tied > boost::tie(entry.second.d_ttd.tv_sec, entry.second.d_ttd.tv_usec)) {
         ret.push_back(std::make_pair(entry.first, entry.second.d_parameter));
       }