[IPLUG/AU] add IParam::mIsMeta and related setter/getter in order to get params that...
[wdl/wdl-ol.git] / WDL / jnetlib / asyncdns.h
blob6c212b537e2315ed1964168a68346965f47850bc
1 /*
2 ** JNetLib
3 ** Copyright (C) 2008 Cockos Inc
4 ** Copyright (C) 2000-2001 Nullsoft, Inc.
5 ** Author: Justin Frankel
6 ** File: asyncdns.h - JNL portable asynchronous DNS interface
7 ** License: see jnetlib.h
8 **
9 ** Usage:
10 ** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries.
11 ** 2. call resolve() to resolve a hostname into an address. The return value of
12 ** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
13 ** try calling resolve() with the same hostname in a few hundred milliseconds
14 ** or so), or -1 on error (i.e. the host can't resolve).
15 ** 3. call reverse() to do reverse dns (ala resolve()).
16 ** 4. enjoy.
19 #ifndef _ASYNCDNS_H_
20 #define _ASYNCDNS_H_
22 #include <time.h>
24 #ifndef JNL_NO_DEFINE_INTERFACES
25 class JNL_IAsyncDNS
27 public:
28 virtual ~JNL_IAsyncDNS() { }
29 virtual int resolve(const char *hostname, unsigned int *addr)=0; // return 0 on success, 1 on wait, -1 on unresolvable
30 virtual int reverse(unsigned int addr, char *hostname)=0; // return 0 on success, 1 on wait, -1 on unresolvable. hostname must be at least 256 bytes.
32 #define JNL_AsyncDNS_PARENTDEF : public JNL_IAsyncDNS
33 #else
34 #define JNL_IAsyncDNS JNL_AsyncDNS
35 #define JNL_AsyncDNS_PARENTDEF
36 #endif
39 #ifndef JNL_NO_IMPLEMENTATION
41 class JNL_AsyncDNS JNL_AsyncDNS_PARENTDEF
43 public:
44 JNL_AsyncDNS(int max_cache_entries=64);
45 ~JNL_AsyncDNS();
47 int resolve(const char *hostname, unsigned int *addr); // return 0 on success, 1 on wait, -1 on unresolvable
48 int reverse(unsigned int addr, char *hostname); // return 0 on success, 1 on wait, -1 on unresolvable. hostname must be at least 256 bytes.
50 private:
51 typedef struct
53 time_t last_used; // timestamp.
54 char resolved;
55 char mode; // 1=reverse
56 char hostname[256];
57 unsigned int addr;
59 cache_entry;
61 cache_entry *m_cache;
62 int m_cache_size;
63 volatile int m_thread_kill;
64 #ifdef _WIN32
65 HANDLE m_thread;
66 static unsigned WINAPI _threadfunc(void *_d);
67 #else
68 pthread_t m_thread;
69 static unsigned int _threadfunc(void *_d);
70 #endif
71 void makesurethreadisrunning(void);
74 #endif // !JNL_NO_IMPLEMENTATION
76 #endif //_ASYNCDNS_H_