/* */ #ifndef D_ASYNC_NAME_RESOLVER_MAN_H #define D_ASYNC_NAME_RESOLVER_MAN_H #include "common.h" #include #include #include 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& 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_[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