Chromium Code Reviews| Index: net/base/dns_query.h |
| diff --git a/net/base/dns_query.h b/net/base/dns_query.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9bb754ecc1f48abd8945932ad12926f85ada0896 |
| --- /dev/null |
| +++ b/net/base/dns_query.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_BASE_DNS_QUERY_H_ |
| +#define NET_BASE_DNS_QUERY_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "net/base/address_family.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/base/net_util.h" |
| + |
| +namespace net{ |
| + |
| +// A class that encapsulates bits and pieces related to DNS request processing. |
| +class DnsQuery { |
| + public: |
| + // Constructs an object containing an IOBuffer with raw DNS query string |
| + // for |hostname| with the given |address_family|; |port| is here due to |
| + // legacy -- getaddrinfo() takes service name, which is mapped to some |
| + // port and returns sockaddr_in structures with ports filled in, so do we |
| + // -- look at DnsResponse::Parse() to see where it is used. |
| + |
| + // Every generated object has a different ID, hence two objects generated |
|
cbentzel
2011/06/02 21:27:13
Thanks for this comment.
You may want to clarify
cbentzel
2011/06/02 21:27:13
Why did you skip the factory approach? That way yo
agayev
2011/06/02 22:33:26
Done.
agayev
2011/06/02 22:33:26
It looked ugly, with much redundancy. Also, I do
cbentzel
2011/06/03 01:58:46
OK, that's reasonable.
|
| + // with the same set of constructor arguments are not equal. |
| + DnsQuery(const std::string& hostname, AddressFamily address_family, int port); |
| + |
| + // Returns true if the constructed object was valid. |
| + bool IsValid() const { return io_buffer_.get() != NULL; } |
| + |
| + // DnsQuery field accessors. |
|
cbentzel
2011/06/02 21:27:13
You should comment that these can only be called i
agayev
2011/06/02 22:33:26
Done.
|
| + int port() const; |
| + uint16 id() const; |
| + uint16 qtype() const; |
| + AddressFamily address_family() const; |
| + const std::string& hostname() const; |
| + |
| + // IOBuffer accessor to be used for writing out the query. |
| + IOBufferWithSize* io_buffer(); |
| + |
| + private: |
| + // Port to be used by corresponding DnsResponse when filling sockaddr_ins |
| + // to be returned. |
| + int port_; |
| + |
| + // ID of the query; changes on each io_buffer_ access. |
| + uint16 id_; |
| + |
| + // Type of query, currently, either A or AAAA. |
| + uint16 qtype_; |
| + |
| + // Address family of the query; used when constructing new object from |
| + // this one. |
| + AddressFamily address_family_; |
| + |
| + // Hostname that we are trying to resolve. |
| + std::string hostname_; |
| + |
| + // Contains query bytes to be consumed by higher level Write() call. |
| + scoped_refptr<IOBufferWithSize> io_buffer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DnsQuery); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_BASE_DNS_QUERY_H_ |