]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Replace Socket * by an fd in PacketID and fix GenUDPQueryResponse to
authorOtto <otto.moerbeek@open-xchange.com>
Mon, 3 May 2021 10:48:03 +0000 (12:48 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Mon, 3 May 2021 10:53:28 +0000 (12:53 +0200)
use fd instead of sock, which should only be used for tcp.

Also reorder PacketID fields so that large fields come before small ones and use modern init.

pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/syncres.hh

index 2ee539cfb642bfdd7325111264d580557f2ccba5..8da5d8112deddbf0b8cf54c0551dc805d274269a 100644 (file)
@@ -401,7 +401,7 @@ static void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var);
 LWResult::Result asendtcp(const string& data, Socket* sock)
 {
   PacketID pident;
-  pident.sock=sock;
+  pident.tcpsock=sock->getHandle();
   pident.outMSG=data;
 
   t_fdm->addWriteFD(sock->getHandle(), handleTCPClientWritable, pident);
@@ -429,7 +429,7 @@ LWResult::Result arecvtcp(string& data, const size_t len, Socket* sock, const bo
 {
   data.clear();
   PacketID pident;
-  pident.sock=sock;
+  pident.tcpsock=sock->getHandle();
   pident.inNeeded=len;
   pident.inIncompleteOkay=incompleteOkay;
   t_fdm->addReadFD(sock->getHandle(), handleTCPClientReadable, pident);
@@ -485,7 +485,7 @@ string GenUDPQueryResponse(const ComboAddress& dest, const string& query)
   s.send(query);
 
   PacketID pident;
-  pident.sock=&s;
+  pident.fd=s.getHandle();
   pident.remote=dest;
   pident.type=0;
   t_fdm->addReadFD(s.getHandle(), handleGenUDPQueryResponse, pident);
index b583435440177f8331a50fd0447d01d2a833ef62..ef0b7bc844063f93a75def86ed67ab36b6b416f3 100644 (file)
@@ -917,7 +917,7 @@ static string* pleaseGetCurrentQueries()
     const double spent = g_networkTimeoutMsec - (DiffTime(now, mthread.ttd) * 1000);
     ostr << (fmt 
              % pident.domain.toLogString() /* ?? */ % DNSRecordContent::NumberToType(pident.type) 
-             % pident.remote.toString() % (pident.sock ? 'Y' : 'n')
+             % pident.remote.toString() % (pident.tcpsock ? 'Y' : 'n')
              % (pident.fd == -1 ? 'Y' : 'n')
              % (spent > 0 ? spent : '0')
              );
index bc09d5dcfced2356f29015644fc03a1c7720e933..f4d8f2790a8835a5b6450eef90c275ff2ecd03be 100644 (file)
@@ -925,38 +925,39 @@ LWResult::Result arecvtcp(string& data, size_t len, Socket* sock, bool incomplet
 
 struct PacketID
 {
-  PacketID() : id(0), type(0), sock(0), inNeeded(0), inIncompleteOkay(false), outPos(0), nearMisses(0), fd(-1), closed(false)
+  PacketID()
   {
     remote.reset();
   }
 
-  uint16_t id;  // wait for a specific id/remote pair
-  uint16_t type;             // and this is its type
   ComboAddress remote;  // this is the remote
   DNSName domain;             // this is the question
 
-  Socket* sock;  // or wait for an event on a TCP fd
   string inMSG; // they'll go here
-  size_t inNeeded; // if this is set, we'll read until inNeeded bytes are read
-  bool inIncompleteOkay;
-
   string outMSG; // the outgoing message that needs to be sent
-  string::size_type outPos;    // how far we are along in the outMSG
 
   typedef set<uint16_t > chain_t;
   mutable chain_t chain;
-  mutable uint32_t nearMisses; // number of near misses - host correct, id wrong
-  int fd;
-  mutable bool closed; // Processing already started, don't accept new chained ids
+  size_t inNeeded{0}; // if this is set, we'll read until inNeeded bytes are read
+  string::size_type outPos{0};    // how far we are along in the outMSG
+  mutable uint32_t nearMisses{0}; // number of near misses - host correct, id wrong
+  int fd{-1};
+  int tcpsock{0};  // or wait for an event on a TCP fd
+  mutable bool closed{false}; // Processing already started, don't accept new chained ids
+  bool inIncompleteOkay{false};
+  uint16_t id{0};  // wait for a specific id/remote pair
+  uint16_t type{0};             // and this is its type
 
   bool operator<(const PacketID& b) const
   {
-    int ourSock= sock ? sock->getHandle() : 0;
-    int bSock = b.sock ? b.sock->getHandle() : 0;
-    if( tie(remote, ourSock, type) < tie(b.remote, bSock, b.type))
+    int ourSock= tcpsock;
+    int bSock = b.tcpsock;
+    if (tie(remote, ourSock, type) < tie(b.remote, bSock, b.type)) {
       return true;
-    if( tie(remote, ourSock, type) > tie(b.remote, bSock, b.type))
+    }
+    if (tie(remote, ourSock, type) > tie(b.remote, bSock, b.type)) {
       return false;
+    }
 
     return tie(fd, id, domain) < tie(b.fd, b.id, b.domain);
   }
@@ -966,12 +967,14 @@ struct PacketIDBirthdayCompare: public std::binary_function<PacketID, PacketID,
 {
   bool operator()(const PacketID& a, const PacketID& b) const
   {
-    int ourSock= a.sock ? a.sock->getHandle() : 0;
-    int bSock = b.sock ? b.sock->getHandle() : 0;
-    if( tie(a.remote, ourSock, a.type) < tie(b.remote, bSock, b.type))
+    int ourSock= a.tcpsock;
+    int bSock = b.tcpsock;
+    if (tie(a.remote, ourSock, a.type) < tie(b.remote, bSock, b.type)) {
       return true;
-    if( tie(a.remote, ourSock, a.type) > tie(b.remote, bSock, b.type))
+    }
+    if (tie(a.remote, ourSock, a.type) > tie(b.remote, bSock, b.type)) {
       return false;
+    }
 
     return a.domain < b.domain;
   }