libevent是一個可編寫高速可移植非阻塞io應用的開源網絡庫。它包含不少組件,主要有evutil、event、eventbase、bufferevent、evbuffer、evhttp、evdns、evrpc等。網絡
libevent提供了一個異步dns解析器,如下是簡單的實現:異步
struct event_base = event_init(); evdns_init(); evdns_resolve_ipv4("www.baidu.com", 0, dns_call_back, NULL); event_dispatch(); event_base_free(base); void dns_callback(int result, char type, int count, int ttl, void *address, void *arg) { struct in_addr *addrs = (struct in_addr*)address; char *ip = inet_ntoa(affrs[0]); }