From 66d4ce9c4b012862768db302455098f52a6e34c3 Mon Sep 17 00:00:00 2001 From: Otto Date: Tue, 2 Mar 2021 16:31:13 +0100 Subject: [PATCH] Write 2-byte header and request in one write call. --- pdns/sdig.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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"); } } -- 2.47.2