forked from aria2/aria2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsyncNameResolverMan.h
102 lines (92 loc) · 3.86 KB
/
AsyncNameResolverMan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_ASYNC_NAME_RESOLVER_MAN_H
#define D_ASYNC_NAME_RESOLVER_MAN_H
#include "common.h"
#include <vector>
#include <string>
#include <memory>
namespace aria2 {
class AsyncNameResolver;
class DownloadEngine;
class Command;
class Option;
class AsyncNameResolverMan {
public:
AsyncNameResolverMan();
// Destructor does not call disableNameResolverCheck(). Application
// must call it before the destruction of this object.
~AsyncNameResolverMan();
// Enable IPv4 address lookup. default: true
void setIPv4(bool ipv4) { ipv4_ = ipv4; }
// Enable IPv6 address lookup. default: true
void setIPv6(bool ipv6) { ipv6_ = ipv6; }
// Returns true if asynchronous name resolution has been started.
bool started() const;
// Starts asynchronous name resolution.
void startAsync(const std::string& hostname, DownloadEngine* e,
Command* command);
// Appends resolved addresses to |res|.
void getResolvedAddress(std::vector<std::string>& res) const;
// Adds resolvers to DownloadEngine to check event notification.
void setNameResolverCheck(DownloadEngine* e, Command* command);
// Removes resolvers from DownloadEngine.
void disableNameResolverCheck(DownloadEngine* e, Command* command);
// Returns true if any of resolvers are added in DownloadEngine.
bool resolverChecked() const { return resolverCheck_; }
// Returns status value: 0 for inprogress, 1 for success and -1 for
// failure.
int getStatus() const;
// Returns last error string
const std::string& getLastError() const;
// Resets state. Also removes resolvers from DownloadEngine.
void reset(DownloadEngine* e, Command* command);
private:
void startAsyncFamily(const std::string& hostname, int family,
DownloadEngine* e, Command* command);
void setNameResolverCheck(size_t resolverIndex, DownloadEngine* e,
Command* command);
void disableNameResolverCheck(size_t index, DownloadEngine* e,
Command* command);
std::shared_ptr<AsyncNameResolver> asyncNameResolver_[2];
size_t numResolver_;
int resolverCheck_;
bool ipv4_;
bool ipv6_;
};
void configureAsyncNameResolverMan(AsyncNameResolverMan* asyncNameResolverMan,
Option* option);
} // namespace aria2
#endif // D_ASYNC_NAME_RESOLVER_MAN_H