From: bert hubert Date: Fri, 26 Jan 2018 09:06:11 +0000 (+0100) Subject: remove selectmplexer reference from nproxy and generalize getMplexer() so nproxy... X-Git-Tag: dnsdist-1.3.0~117^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4226cfd07e0fb66d1f3b1e0363e97d1206303f4b;p=pdns remove selectmplexer reference from nproxy and generalize getMplexer() so nproxy and dnsdist can both use it. Removed some final traces from SelectFDMplexer from mplexer.hh too. --- diff --git a/pdns/mplexer.hh b/pdns/mplexer.hh index 880abd18b..ed0f2a02a 100644 --- a/pdns/mplexer.hh +++ b/pdns/mplexer.hh @@ -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 diff --git a/pdns/nproxy.cc b/pdns/nproxy.cc index d6999e4bc..705a1fce1 100644 --- a/pdns/nproxy.cc +++ b/pdns/nproxy.cc @@ -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(); } diff --git a/pdns/pollmplexer.cc b/pdns/pollmplexer.cc index b8c565975..37f78290a 100644 --- a/pdns/pollmplexer.cc +++ b/pdns/pollmplexer.cc @@ -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: diff --git a/pdns/snmp-agent.cc b/pdns/snmp-agent.cc index eecb36ebf..3187a56d7 100644 --- a/pdns/snmp-agent.cc +++ b/pdns/snmp-agent.cc @@ -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!"); }