首页 > 代码库 > libevent

libevent

  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