From: Otto Date: Tue, 2 Mar 2021 15:31:13 +0000 (+0100) Subject: Write 2-byte header and request in one write call. X-Git-Tag: dnsdist-1.6.0-alpha2~9^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10132%2Fhead;p=thirdparty%2Fpdns.git Write 2-byte header and request in one write call. --- diff --git a/pdns/sdig.cc b/pdns/sdig.cc index bec3918ad2..c36e22ae23 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -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(len >> 8)); + question.push_back(static_cast(len & 0xff)); + question.append(packet.begin(), packet.end()); + if (handler.write(question.data(), question.size(), timeout) != question.size()) { throw PDNSException("tcp write failed"); } }