OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_DNS_QUERY_H_ | |
6 #define NET_BASE_DNS_QUERY_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "net/base/address_family.h" | |
12 #include "net/base/io_buffer.h" | |
13 #include "net/base/net_util.h" | |
14 | |
15 namespace net{ | |
16 | |
17 // A class that encapsulates bits and pieces related to DNS request processing. | |
18 class DnsQuery { | |
19 public: | |
20 // Constructs an object containing an IOBuffer with raw DNS query string | |
21 // for |hostname| with the given |address_family|; |port| is here due to | |
22 // legacy -- getaddrinfo() takes service name, which is mapped to some | |
23 // port and returns sockaddr_in structures with ports filled in, so do we | |
24 // -- look at DnsResponse::Parse() to see where it is used. | |
25 | |
26 // 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.
| |
27 // with the same set of constructor arguments are not equal. | |
28 DnsQuery(const std::string& hostname, AddressFamily address_family, int port); | |
29 | |
30 // Returns true if the constructed object was valid. | |
31 bool IsValid() const { return io_buffer_.get() != NULL; } | |
32 | |
33 // 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.
| |
34 int port() const; | |
35 uint16 id() const; | |
36 uint16 qtype() const; | |
37 AddressFamily address_family() const; | |
38 const std::string& hostname() const; | |
39 | |
40 // IOBuffer accessor to be used for writing out the query. | |
41 IOBufferWithSize* io_buffer(); | |
42 | |
43 private: | |
44 // Port to be used by corresponding DnsResponse when filling sockaddr_ins | |
45 // to be returned. | |
46 int port_; | |
47 | |
48 // ID of the query; changes on each io_buffer_ access. | |
49 uint16 id_; | |
50 | |
51 // Type of query, currently, either A or AAAA. | |
52 uint16 qtype_; | |
53 | |
54 // Address family of the query; used when constructing new object from | |
55 // this one. | |
56 AddressFamily address_family_; | |
57 | |
58 // Hostname that we are trying to resolve. | |
59 std::string hostname_; | |
60 | |
61 // Contains query bytes to be consumed by higher level Write() call. | |
62 scoped_refptr<IOBufferWithSize> io_buffer_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(DnsQuery); | |
65 }; | |
66 | |
67 } // namespace net | |
68 | |
69 #endif // NET_BASE_DNS_QUERY_H_ | |
OLD | NEW |