Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: net/dns/dns_query.cc

Issue 2790823003: net: calculate dns header size only once per query/response (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/dns_response.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_query.cc
diff --git a/net/dns/dns_query.cc b/net/dns/dns_query.cc
index aa9bc70454e7f15f0660864f357093572ba91ca9..ac74ca479615a31abd407cd12ca2572b126637b0 100644
--- a/net/dns/dns_query.cc
+++ b/net/dns/dns_query.cc
@@ -13,14 +13,19 @@
namespace net {
+namespace {
+
+const size_t kHeaderSize = sizeof(dns_protocol::Header);
+
+} // namespace
+
// DNS query consists of a 12-byte header followed by a question section.
// For details, see RFC 1035 section 4.1.1. This header template sets RD
// bit, which directs the name server to pursue query recursively, and sets
// the QDCOUNT to 1, meaning the question section has a single entry.
DnsQuery::DnsQuery(uint16_t id, const base::StringPiece& qname, uint16_t qtype)
: qname_size_(qname.size()),
- io_buffer_(
- new IOBufferWithSize(sizeof(dns_protocol::Header) + question_size())),
+ io_buffer_(new IOBufferWithSize(kHeaderSize + question_size())),
header_(reinterpret_cast<dns_protocol::Header*>(io_buffer_->data())) {
DCHECK(!DNSDomainToString(qname).empty());
*header_ = {};
@@ -29,8 +34,8 @@ DnsQuery::DnsQuery(uint16_t id, const base::StringPiece& qname, uint16_t qtype)
header_->qdcount = base::HostToNet16(1);
// Write question section after the header.
- base::BigEndianWriter writer(
- io_buffer_->data() + sizeof(dns_protocol::Header), question_size());
+ base::BigEndianWriter writer(io_buffer_->data() + kHeaderSize,
+ question_size());
writer.WriteBytes(qname.data(), qname.size());
writer.WriteU16(qtype);
writer.WriteU16(dns_protocol::kClassIN);
@@ -48,20 +53,18 @@ uint16_t DnsQuery::id() const {
}
base::StringPiece DnsQuery::qname() const {
- return base::StringPiece(io_buffer_->data() + sizeof(dns_protocol::Header),
- qname_size_);
+ return base::StringPiece(io_buffer_->data() + kHeaderSize, qname_size_);
}
uint16_t DnsQuery::qtype() const {
uint16_t type;
- base::ReadBigEndian<uint16_t>(
- io_buffer_->data() + sizeof(dns_protocol::Header) + qname_size_, &type);
+ base::ReadBigEndian<uint16_t>(io_buffer_->data() + kHeaderSize + qname_size_,
+ &type);
return type;
}
base::StringPiece DnsQuery::question() const {
- return base::StringPiece(io_buffer_->data() + sizeof(dns_protocol::Header),
- question_size());
+ return base::StringPiece(io_buffer_->data() + kHeaderSize, question_size());
}
void DnsQuery::set_flags(uint16_t flags) {
« no previous file with comments | « no previous file | net/dns/dns_response.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698