]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Write 2-byte header and request in one write call. 10132/head
authorOtto <otto.moerbeek@open-xchange.com>
Tue, 2 Mar 2021 15:31:13 +0000 (16:31 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Tue, 2 Mar 2021 15:31:13 +0000 (16:31 +0100)
pdns/sdig.cc

index bec3918ad27e58df45fbcaa52edeef92f9734c66..c36e22ae23d2f28a1748a508155c29d1968916f2 100644 (file)
@@ -425,10 +425,15 @@ try {
       fillPacket(packet, it.first, it.second, dnssec, ednsnm, recurse, xpfcode,
                  xpfversion, xpfproto, xpfsrc, xpfdst, qclass, counter);
       counter++;
-      uint16_t len = htons(packet.size());
-      if (handler.write(&len, sizeof(len), timeout) != sizeof(len))
-        throw PDNSException("tcp write failed");
-      if (handler.write(packet.data(), packet.size(), timeout) != packet.size()) {
+
+      // Prefer to do a single write, so that fastopen can send all the data on SYN
+      uint16_t len = packet.size();
+      string question;
+      question.reserve(sizeof(len) + packet.size());
+      question.push_back(static_cast<char>(len >> 8));
+      question.push_back(static_cast<char>(len & 0xff));
+      question.append(packet.begin(), packet.end());
+      if (handler.write(question.data(), question.size(), timeout) != question.size()) {
         throw PDNSException("tcp write failed");
       }
     }