wac_network_dns.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. ** JNetLib
  3. ** Copyright (C) 2000-2007 Nullsoft, Inc.
  4. ** Author: Justin Frankel
  5. ** File: asyncdns.h - JNL portable asynchronous DNS interface
  6. ** License: see jnetlib.h
  7. **
  8. ** Usage:
  9. ** 1. Create wa::Components::WAC_Network_AsyncDNS object, optionally with the number of cache entries.
  10. ** 2. call resolve() to resolve a hostname into an address. The return value of
  11. ** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
  12. ** try calling resolve() with the same hostname in a few hundred milliseconds
  13. ** or so), or -1 on error (i.e. the host can't resolve).
  14. ** 3. call reverse() to do reverse dns (ala resolve()).
  15. ** 4. enjoy.
  16. */
  17. #ifndef NULLSOFT_WAC_NETWORK_ASYNCDNS_H
  18. #define NULLSOFT_WAC_NETWORK_ASYNCDNS_H
  19. #include "netinc.h"
  20. #include "wac_network_dns_api.h"
  21. struct cache_entry;
  22. //#define JNL_AUTODNS ((wa::Components::WAC_Network_AsyncDNS *)-1)
  23. //enum
  24. //{
  25. // DNS_RESOLVE_UNRESOLVABLE = -1,
  26. // DNS_RESOLVE_SUCCESS = 0,
  27. // DNS_RESOLVE_WAIT = 1,
  28. //};
  29. //
  30. //enum
  31. //{
  32. // DNS_REVERSE_UNRESOLVABLE = -1,
  33. // DNS_REVERSE_SUCCESS = 0,
  34. // DNS_REVERSE_WAIT = 1,
  35. //};
  36. namespace wa
  37. {
  38. namespace Components
  39. {
  40. class WAC_Network_AsyncDNS : public api_dns
  41. {
  42. public:
  43. WAC_Network_AsyncDNS( int max_cache_entries = 64 );
  44. ~WAC_Network_AsyncDNS();
  45. int resolve( const char *hostname, unsigned short port, addrinfo **addr, int sockettype ); // return 0 on success, 1 on wait, -1 on unresolvable
  46. static int resolvenow( const char *hostname, unsigned short port, addrinfo **addr, int sockettype ); // return 0 on success, -1 on unresolvable
  47. private:
  48. cache_entry *m_cache;
  49. int m_cache_size;
  50. volatile int m_thread_kill;
  51. #ifdef _WIN32
  52. HANDLE m_thread;
  53. static unsigned long WINAPI _threadfunc( LPVOID _d );
  54. #else
  55. pthread_t m_thread;
  56. static unsigned int _threadfunc( void *_d );
  57. #endif
  58. void makesurethreadisrunning( void );
  59. protected:
  60. RECVS_DISPATCH;
  61. };
  62. }
  63. }
  64. #endif //!NULLSOFT_WAC_NETWORK_ASYNCDNS_H