1. 程式人生 > >libevent

libevent

cal patch dispatch llb () buffer ack toa call

  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]); }

libevent