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_RESPONSE_H_ | |
6 #define NET_BASE_DNS_RESPONSE_H_ | |
7 #pragma once | |
8 | |
9 #include "net/base/dns_query.h" | |
10 | |
11 namespace net{ | |
12 | |
13 class AddressList; | |
14 | |
15 // A class that encapsulates bits and pieces related to DNS response | |
16 // processing. | |
17 class DnsResponse { | |
cbentzel
2011/06/01 17:17:03
DnsResponse is a bit different than I expected. I
| |
18 public: | |
19 // Constructs a response object with an IOBuffer large enough to read | |
20 // every possible; |query| is a pointer to the DnsQuery for which |this| | |
21 // is supposed to be a response. | |
22 DnsResponse(DnsQuery* query); | |
cbentzel
2011/06/01 17:17:03
Mark this constructor as explicit.
cbentzel
2011/06/01 17:17:03
You should specify what the lifetime expectations
agayev
2011/06/01 19:15:01
Done.
| |
23 | |
24 // Internal buffer accessor into which actual bytes of response to be | |
25 // read. | |
26 IOBuffer* io_buffer() { return io_buffer_.get(); } | |
27 | |
28 // Returns the size of the DNS response. | |
29 int size() const { return size_; } | |
30 | |
31 // Parses response of size nbytes and puts address into |results|, | |
32 // returns whether succeeded or not. | |
33 bool Parse(int nbytes, AddressList* results); | |
34 | |
35 // Error code accessor. | |
36 int error() const { return error_; } | |
37 | |
38 private: | |
39 FRIEND_TEST_ALL_PREFIXES(DnsResponseTest, ResponseWithCnameA); | |
40 | |
41 // Gives access to the response bytes directly, used by tests. | |
42 char* data() { return io_buffer_->data(); } | |
43 | |
44 // Error code, currently either 0 or EAI_NONAME, will be amended with | |
45 // specific error codes in the future. | |
46 int error_; | |
47 | |
48 // Size of the response; initially it is one byte larger than maximum DNS | |
49 // response size to allow reading all possible responses as well as | |
50 // detecting oversized ones, adjusted once the actual response is read. | |
51 int size_; | |
52 | |
53 // The matching query; |this| is the response for this query. | |
54 DnsQuery* const query_; | |
55 | |
56 // Buffer into which response bytes are read. | |
57 scoped_refptr<IOBufferWithSize> io_buffer_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(DnsResponse); | |
60 }; | |
61 | |
62 } // namespace net | |
63 | |
64 #endif // NET_BASE_DNS_RESPONSE_H_ | |
OLD | NEW |