]> granicus.if.org Git - pdns/commitdiff
remove selectmplexer reference from nproxy and generalize getMplexer() so nproxy...
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 26 Jan 2018 09:06:11 +0000 (10:06 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 26 Jan 2018 09:06:11 +0000 (10:06 +0100)
Removed some final traces from SelectFDMplexer from mplexer.hh too.

pdns/mplexer.hh
pdns/nproxy.cc
pdns/pollmplexer.cc
pdns/snmp-agent.cc

index 880abd18be2a9867c1d8e4a25a11798fa7015658..ed0f2a02a7f59d3eb24f17c8e229e7df07a61cdc 100644 (file)
@@ -67,6 +67,8 @@ public:
   virtual ~FDMultiplexer()
   {}
 
+  static FDMultiplexer* getMultiplexerSilent();
+  
   /* tv will be updated to 'now' before run returns */
   /* timeout is in ms */
   virtual int run(struct timeval* tv, int timeout=500) = 0;
@@ -160,23 +162,6 @@ protected:
   }
 };
 
-class SelectFDMultiplexer : public FDMultiplexer
-{
-public:
-  SelectFDMultiplexer()
-  {}
-  virtual ~SelectFDMultiplexer()
-  {}
-
-  virtual int run(struct timeval* tv, int timeout=500);
-
-  virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const funcparam_t& parameter);
-  virtual void removeFD(callbackmap_t& cbmap, int fd);
-  std::string getName()
-  {
-    return "select";
-  }
-};
 
 #endif
 
index d6999e4bc012bf5704d9212a9be9336190041ced..705a1fce1d719502d5bdcbc5993fafdf1345eb9d 100644 (file)
@@ -52,7 +52,7 @@ po::variables_map g_vm;
 
 StatBag S;
 
-SelectFDMultiplexer g_fdm;
+FDMultiplexer* g_fdm;
 int g_pdnssocket;
 bool g_verbose;
 
@@ -218,6 +218,11 @@ try
   reportAllTypes();
   openlog("nproxy", LOG_NDELAY | LOG_PID, LOG_DAEMON);
 
+  g_fdm = FDMultiplexer::getMultiplexerSilent();
+  if(!g_fdm) {
+    throw std::runtime_error("Could not enable a multiplexer");
+  }
+  
   po::options_description desc("Allowed options");
   desc.add_options()
     ("help,h", "produce help message")
@@ -273,7 +278,7 @@ try
     if(::bind(sock,(sockaddr*) &local, local.getSocklen()) < 0)
       throw runtime_error("Binding socket for incoming packets to '"+ local.toStringWithPort()+"': "+stringerror());
 
-    g_fdm.addReadFD(sock, handleOutsideUDPPacket); // add to fdmultiplexer for each socket
+    g_fdm->addReadFD(sock, handleOutsideUDPPacket); // add to fdmultiplexer for each socket
     syslogFmt(boost::format("Listening for external notifications on address %s") % local.toStringWithPort());
   }
 
@@ -294,7 +299,7 @@ try
 
   syslogFmt(boost::format("Sending notifications from %s to internal address %s") % originAddress.toString() % pdns.toStringWithPort());
 
-  g_fdm.addReadFD(g_pdnssocket, handleInsideUDPPacket);
+  g_fdm->addReadFD(g_pdnssocket, handleInsideUDPPacket);
 
   int null_fd=open("/dev/null",O_RDWR); /* open stdin */
   if(null_fd < 0)
@@ -332,7 +337,7 @@ try
   struct timeval now;
   for(;;) {
     gettimeofday(&now, 0);
-    g_fdm.run(&now);
+    g_fdm->run(&now);
     // check for notifications that have been outstanding for more than 10 seconds
     expireOldNotifications();
   }
index b8c565975ce62da7e84db9093b7df1dff387baae..37f78290aa2a7dff7ed0140279e02ff425e891cd 100644 (file)
@@ -8,6 +8,23 @@
 #include "misc.hh"
 #include "namespaces.hh"
 
+FDMultiplexer* FDMultiplexer::getMultiplexerSilent()
+{
+  FDMultiplexer* ret = nullptr;
+  for(const auto& i : FDMultiplexer::getMultiplexerMap()) {
+    try {
+      ret = i.second();
+      return ret;
+    }
+    catch(const FDMultiplexerException& fe) {
+    }
+    catch(...) {
+    }
+  }
+  return ret;
+}
+
+
 class PollFDMultiplexer : public FDMultiplexer
 {
 public:
index eecb36ebf82e0b84fe0ad52c5049dac66de5a467..3187a56d72033ec98c992235d97a9254f32d05d8 100644 (file)
@@ -90,28 +90,12 @@ void SNMPAgent::handleSNMPQueryCB(int fd, FDMultiplexer::funcparam_t& var)
   (*agent)->handleSNMPQueryEvent(fd);
 }
 
-static FDMultiplexer* getMultiplexer()
-{
-  FDMultiplexer* ret = nullptr;
-  for(const auto& i : FDMultiplexer::getMultiplexerMap()) {
-    try {
-      ret = i.second();
-      return ret;
-    }
-    catch(const FDMultiplexerException& fe) {
-    }
-    catch(...) {
-    }
-  }
-  return ret;
-}
-
 #endif /* HAVE_NET_SNMP */
 
 void SNMPAgent::worker()
 {
 #ifdef HAVE_NET_SNMP
-  FDMultiplexer* mplexer = getMultiplexer();
+  FDMultiplexer* mplexer = FDMultiplexer::getMultiplexerSilent();
   if (mplexer == nullptr) {
     throw std::runtime_error("No FD multiplexer found for the SNMP agent!");
   }