]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
remove some dead code, add silly special cased 'waitFor2Data' to wait on 2 fds simult...
authorBert Hubert <bert.hubert@netherlabs.nl>
Mon, 14 Feb 2011 10:53:26 +0000 (10:53 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Mon, 14 Feb 2011 10:53:26 +0000 (10:53 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2011 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/misc.cc
pdns/misc.hh

index b39e6e7d1d8f0b227d89be9d0e2bebfe333b9041..d47fb41cf41ad2683e23043f5cce321431743ced 100644 (file)
@@ -317,11 +317,45 @@ int waitForRWData(int fd, bool waitForRead, int seconds, int useconds)
 
   ret = poll(&pfd, 1, seconds * 1000 + useconds/1000);
   if ( ret == -1 )
-    errno = ETIMEDOUT;
+    errno = ETIMEDOUT; // ???
 
   return ret;
 }
 
+// returns -1 in case if error, 0 if no data is available, 1 if there is. In the first two cases, errno is set
+int waitFor2Data(int fd1, int fd2, int seconds, int useconds, int*fd)
+{
+  int ret;
+
+  struct pollfd pfds[2];
+  memset(&pfds[0], 0, 2*sizeof(struct pollfd));
+  pfds[0].fd = fd1;
+  pfds[1].fd = fd2;
+  
+  pfds[0].events= pfds[1].events = POLLIN;
+
+  int nsocks = 1 + (fd2 >= 0); // fd2 can optionally be -1
+
+  if(seconds >= 0)
+    ret = poll(pfds, nsocks, seconds * 1000 + useconds/1000);
+  else
+    ret = poll(pfds, nsocks, -1);
+  if(!ret || ret < 0)
+    return ret;
+    
+  if((pfds[0].revents & POLLIN) && !(pfds[1].revents & POLLIN))
+    *fd = pfds[0].fd;
+  else if((pfds[1].revents & POLLIN) && !(pfds[0].revents & POLLIN))
+    *fd = pfds[1].fd;
+  else if(ret == 2) {
+    *fd = pfds[random()%2].fd;
+  }
+  else
+    *fd = -1; // should never happen
+  
+  return 1;
+}
+
 
 string humanDuration(time_t passed)
 {
index c366976cb6992da5e9a7588c4844199aa5b87f12..6e3e714d45f1841e79c017ccd853ea41adfc4067 100644 (file)
@@ -83,6 +83,7 @@ void stripLine(string &line);
 string getHostname();
 string urlEncode(const string &text);
 int waitForData(int fd, int seconds, int useconds=0);
+int waitFor2Data(int fd1, int fd2, int seconds, int useconds, int* fd);
 int waitForRWData(int fd, bool waitForRead, int seconds, int useconds);
 uint16_t getShort(const unsigned char *p);
 uint16_t getShort(const char *p);
@@ -90,26 +91,6 @@ uint32_t getLong(const unsigned char *p);
 uint32_t getLong(const char *p);
 boost::optional<int> logFacilityToLOG(unsigned int facility);
 
-inline void putLong(unsigned char* p, uint32_t val)
-{
-  *p++=(val>>24)&0xff;
-  *p++=(val>>16)&0xff;
-  *p++=(val>>8)&0xff;
-  *p++=(val   )&0xff;
-
-}
-inline void putLong(char* p, uint32_t val)
-{
-  putLong((unsigned char *)p,val);
-}
-
-
-inline uint32_t getLong(unsigned char *p)
-{
-  return (p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
-}
-
-
 struct ServiceTuple
 {
   string host;