2011-01-24 17:05:10 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
|
|
|
|
struct sockaddr ;
|
|
|
|
|
|
|
|
class DNSResolver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DNSResolver() ;
|
|
|
|
~DNSResolver() ;
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
bool getIPAddressFromString(const std::string& server_name,struct sockaddr_storage &addr) ;
|
2011-01-24 17:05:10 -05:00
|
|
|
|
|
|
|
void start_request() ;
|
|
|
|
void reset() ;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum { DNS_DONT_HAVE,DNS_SEARCHING, DNS_HAVE, DNS_LOOKUP_ERROR } ;
|
|
|
|
|
|
|
|
struct AddrInfo
|
|
|
|
{
|
|
|
|
uint32_t state ; // state: Looked-up, not found, have
|
|
|
|
time_t last_lookup_time ; // last lookup time
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage addr ;
|
2011-01-24 17:05:10 -05:00
|
|
|
};
|
|
|
|
friend void *solveDNSEntries(void *p) ;
|
|
|
|
|
|
|
|
RsMutex _rdnsMtx ;
|
|
|
|
bool *_thread_running ;
|
|
|
|
std::map<std::string, AddrInfo> *_addr_map ;
|
|
|
|
};
|