acl/lib_acl_cpp/include/acl_cpp/stdlib/dns_service.hpp

111 lines
3.3 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
2017-06-02 14:47:24 +08:00
#include "../ipc/ipc_service.hpp"
#include "../stream/aio_handle.hpp"
#include "../stream/aio_delay_free.hpp"
#include "string.hpp"
2014-11-19 00:25:21 +08:00
namespace acl
{
class ACL_CPP_API dns_res
{
public:
dns_res(const char* domain) : domain_(domain) {}
~dns_res() { ips_.clear(); }
string domain_;
std::list<string> ips_;
protected:
private:
};
class ACL_CPP_API dns_result_callback
{
public:
dns_result_callback(const char* domain) : domain_(domain) {}
/**
* destroy
*
* delete this
*
2014-11-19 00:25:21 +08:00
*/
virtual void destroy(void) {}
/**
* res.ips_.size() == 0
*
* @param domain {const char*}
* @param res {const dns_res&}
* dns_service
* 访 dns_service
* dns_service 使
2014-11-19 00:25:21 +08:00
*/
virtual void on_result(const char* domain, const dns_res& res) = 0;
/**
*
2014-11-19 00:25:21 +08:00
*/
const string& get_domain() const { return (domain_); }
protected:
virtual ~dns_result_callback() {}
private:
string domain_;
};
class ipc_client;
class ACL_CPP_API dns_service
: public ipc_service
, public aio_delay_free
{
public:
/**
*
* @param nthread {int} > 1 线
* 线
* @param win32_gui {bool}
* _WIN32
*
2014-11-19 00:25:21 +08:00
*/
dns_service(int nthread = 1, bool win32_gui = false);
~dns_service();
/**
*
* @param callback {dns_result_callback*}
* on_result
2014-11-19 00:25:21 +08:00
*/
void lookup(dns_result_callback* callback);
/**
* 线线
*
* @param res {const dns_res&}
2014-11-19 00:25:21 +08:00
*/
void on_result(const dns_res& res);
protected:
/**
*
* @param client {aio_socket_stream*}
2014-11-19 00:25:21 +08:00
*/
virtual void on_accept(aio_socket_stream* client);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* 线 win32
* @param hWnd {HWND}
* @param msg {UINT}
* @param wParam {WPARAM}
* @param lParam {LPARAM}
2014-11-19 00:25:21 +08:00
*/
virtual void win32_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
#endif
private:
std::list<dns_result_callback*> callbacks_;
};
}