From 0d0f9fab07f7b4761180c43d0984a2278a633842 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Wed, 19 Apr 2006 07:46:28 +0000 Subject: [PATCH] add SunOS sysdeps make ports multiplexer work make compiling multiplexers no longer be silent git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@735 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/portsmplexer.cc | 37 ++++++++++++++++--------------- pdns/sysdeps-recursor/FreeBSD.inc | 2 +- pdns/sysdeps-recursor/Linux.inc | 2 +- pdns/sysdeps-recursor/SunOS.inc | 7 ++++++ 4 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 pdns/sysdeps-recursor/SunOS.inc diff --git a/pdns/portsmplexer.cc b/pdns/portsmplexer.cc index 68628c171..34b1b7007 100644 --- a/pdns/portsmplexer.cc +++ b/pdns/portsmplexer.cc @@ -5,18 +5,18 @@ #include "misc.hh" #include #include "syncres.hh" +#include #include using namespace boost; using namespace std; - class PortsFDMultiplexer : public FDMultiplexer { public: PortsFDMultiplexer(); virtual ~PortsFDMultiplexer() { - port_close(d_portfd); + close(d_portfd); } virtual int run(struct timeval* tv); @@ -59,7 +59,7 @@ void PortsFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo { accountingAddFD(cbmap, fd, toDo, parameter); - if(port_associate(port, PORT_SOURCE_FD, fd, (&cbmap == &d_readCallbacks) ? POLLIN : POLLOUT, 0) < 0) { + if(port_associate(d_portfd, PORT_SOURCE_FD, fd, (&cbmap == &d_readCallbacks) ? POLLIN : POLLOUT, 0) < 0) { cbmap.erase(fd); throw FDMultiplexerException("Adding fd to port set: "+stringerror()); } @@ -70,7 +70,7 @@ void PortsFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) if(!cbmap.erase(fd)) throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); - if(port_dissociate(port, PORT_SOURCE_FD, fd) < 0) + if(port_dissociate(d_portfd, PORT_SOURCE_FD, fd) < 0) throw FDMultiplexerException("Removing fd from port set: "+stringerror()); } @@ -80,38 +80,39 @@ int PortsFDMultiplexer::run(struct timeval* now) throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n"); } - struct timeval tv; - tv.tv_sec=0; tv.tv_usec=500000; - int numevents=0; - int ret= port_getn(d_portfd, d_pevents, min(PORT_MAX_LIST, s_maxevents), &numevents, &timeout); + struct timespec timeout; + timeout.tv_sec=0; timeout.tv_nsec=500000000; + unsigned int numevents=1; + int ret= port_getn(d_portfd, d_pevents.get(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeout); gettimeofday(now,0); - if(ret < 0 && errno!=EINTR) + if(ret < 0 && errno!=EINTR && errno!=ETIME) throw FDMultiplexerException("completion port_getn returned error: "+stringerror()); - if(ret==0) // nothing + if((ret < 0 && errno==ETIME) || numevents==0) // nothing return 0; d_inrun=true; - for(int n=0; n < numevents; ++n) { - d_iter=d_readCallbacks.find(d_portevents[n].portev_object); + for(unsigned int n=0; n < numevents; ++n) { + d_iter=d_readCallbacks.find(d_pevents[n].portev_object); if(d_iter != d_readCallbacks.end()) { d_iter->second.d_callback(d_iter->first, d_iter->second.d_parameter); - result = port_associate(d_portfd, PORT_SOURCE_FD, d_portevents[n].portev_object, - POLLIN, d_pevents[n].portev_user); + if(d_readCallbacks.count(d_pevents[n].portev_object) && port_associate(d_portfd, PORT_SOURCE_FD, d_pevents[n].portev_object, + POLLIN, 0) < 0) + throw FDMultiplexerException("Unable to add fd back to ports (read): "+stringerror()); } - d_iter=d_writeCallbacks.find(d_pevents[n].data.fd); + d_iter=d_writeCallbacks.find(d_pevents[n].portev_object); if(d_iter != d_writeCallbacks.end()) { d_iter->second.d_callback(d_iter->first, d_iter->second.d_parameter); - result = port_associate(d_portfd, PORT_SOURCE_FD, d_portevents[n].portev_object, - POLLOUT, d_pevents[n].portev_user); + if(d_writeCallbacks.count(d_pevents[n].portev_object) && port_associate(d_portfd, PORT_SOURCE_FD, d_pevents[n].portev_object, + POLLOUT, 0) < 0) + throw FDMultiplexerException("Unable to add fd back to ports (write): "+stringerror()); } - } diff --git a/pdns/sysdeps-recursor/FreeBSD.inc b/pdns/sysdeps-recursor/FreeBSD.inc index fc99a82b4..357817a4e 100644 --- a/pdns/sysdeps-recursor/FreeBSD.inc +++ b/pdns/sysdeps-recursor/FreeBSD.inc @@ -1,5 +1,5 @@ OPTIONALS:=optional/kqueuemplexer.o optional/kqueuemplexer.o: kqueuemplexer.cc - $(CXX) $(CXXFLAGS) -c $< -o $@ 2> /dev/null; true + $(CXX) $(CXXFLAGS) -c $< -o $@ ; true diff --git a/pdns/sysdeps-recursor/Linux.inc b/pdns/sysdeps-recursor/Linux.inc index dc2e03b8f..4e7a6fb98 100644 --- a/pdns/sysdeps-recursor/Linux.inc +++ b/pdns/sysdeps-recursor/Linux.inc @@ -1,5 +1,5 @@ OPTIONALS:=optional/epollmplexer.o optional/epollmplexer.o: epollmplexer.cc - $(CXX) $(CXXFLAGS) -c $< -o $@ 2> /dev/null ; true + $(CXX) $(CXXFLAGS) -c $< -o $@ ; true diff --git a/pdns/sysdeps-recursor/SunOS.inc b/pdns/sysdeps-recursor/SunOS.inc new file mode 100644 index 000000000..42cf8b0de --- /dev/null +++ b/pdns/sysdeps-recursor/SunOS.inc @@ -0,0 +1,7 @@ +LDFLAGS+=-lresolv -lsocket -lnsl + +OPTIONALS:=optional/portsmplexer.o + +optional/portsmplexer.o: portsmplexer.cc + $(CXX) $(CXXFLAGS) -c $< -o $@ ; true + -- 2.49.0