From: Otto Date: Mon, 3 May 2021 10:48:03 +0000 (+0200) Subject: Replace Socket * by an fd in PacketID and fix GenUDPQueryResponse to X-Git-Tag: auth-4.5.0-alpha1~8^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bf2e213346ef3594df42829b3f931b13f3d9419;p=thirdparty%2Fpdns.git Replace Socket * by an fd in PacketID and fix GenUDPQueryResponse to 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. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2ee539cfb6..8da5d8112d 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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); diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index b583435440..ef0b7bc844 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -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') ); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index bc09d5dcfc..f4d8f2790a 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -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 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_functiongetHandle() : 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; }