Kaushal Shriyan | 13 Nov 14:30 2015

libevent2 repo or rpm binaries for CentOS 6.x


Do i need to enable any repo on CentOS 6.x to install libevent2 or any rpm binary packages?


liu wen | 10 Nov 21:00 2015

can I call event_del() on an event and then use event_add to add it again?

I register an timeout event as below:

struct event * fin_ev = (struct event *)malloc(sizeof(struct event));
event_set(fin_ev, -1, 0, on_fin_timeout, NULL);
event_base_set(base, fin_ev);
event_add(fin_ev, &tv) ;

and when a condition is satisfied when the timeout event is not triggered, I want to remove the event and add it again 

can I do something like:
           event_add(fin_ev, &tv)  


          event_set(fin_ev, -1, 0, on_fin_timeout, NULL);
          event_base_set(base, fin_ev);
           event_add(fin_ev, &tv)  

liu wen | 29 Oct 02:08 2015

how to change event type

if I have set events conn_ev 

event_set(entry->conn_ev, entry->connfd, EV_READ|EV_PERSIST, on_recv, event_arg);
event_base_set(base, entry->conn_ev);
event_add(entry->conn_ev, NULL)

after a number of triggers of this events, I want to make the event become:

event_set(entry->conn_ev, entry->connfd, EV_READ|EV_TIMEOUT, on_recv, event_arg);

that is I want conn_ev to change from EV_READ|EV_PERSIST to EV_READ|EV_TIMEOUT, what should I do?

Reindl Harald | 22 Oct 18:46 2015

Re: Unsubscribe

Am 22.10.2015 um 18:39 schrieb tkaria <at> gmail.com:
> Unsubscribe libevent-users

i don't know any list where you send that to all subscribers, below the 
welcome message after subscribe, people should store that messages 
instead throw them away...........

Welcome to the libevent-users mailing list!

Please save this message for future reference. Thank you.

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo <at> seul.org> with the following
command in the body of your email message:

unsubscribe libevent-users

Roman Gershman | 22 Oct 18:02 2015

using event_base_loop withy timer events

my ebase thread does the following loop

while ((res = event_base_loop(ebase_, EVLOOP_ONCE)) == 1) {

and the other (main) adds timer event that runs every millisecond. It adds the event *after* the ebase thread calls event_base_loop. 

event* ev = event_new(base(), -1, EV_PERSIST | EV_TIMEOUT, &PeriodicCb, data);
CHECK_EQ(0, event_add(ev, &tv));

I see that this event does not run. If I change flags from EVLOOP_ONCE to 0 it does run well.
How should I make event base to realize that the new event is added?



liu wen | 19 Oct 06:01 2015

does libevent2 or "libevent2 on unbutun" trigger EV_READ events unexpectedly ?

I have two laptops, one with fedora system, libevent 
and one with unbuntu system, libevent2

and I have two programs, one has a event related to read() while the other has an event related to pcap(libpcap: normally, when libpcap captures  packet, the event should be triggered)

I notice there are always false events, the read() returns -1 and the error is "Resource temporarily unavailable". the pcap captures 0 packets when the related event is triggered. this is really strange.

when the libpcap program runs on fedora laptop, it works fine

so I'm wondering does libevent2 or "libevent2 on unbutun" trigger EV_READ events unexpectedly ?
wwyyxx26 | 13 Oct 14:51 2015

Paired bufferevents can't let event_base_dispatch block?

I want use paired bufferevents to pass message to the thread whitch called event_base_dispatch.

struct bufferevent *pairbev[2];
bufferevent_pair_new(ebase, BEV_OPT_THREADSAFE, pairbev);
bufferevent_setcb(pairbev[1], Static_ReadCallback, NULL, Static_EventCallback, this);
bufferevent_enable(pairbev[1], EV_READ|EV_WRITE);

but I found that when the event_base has only pairbev[1] event on it, it can't let the event_base_dispatch block, this function return with value 1 Immediately.
I had tried both in linux and windows, it looks like the same. 
Does it a bug or was there something i Ignored?


liu wen | 12 Oct 23:06 2015

how the difference of libevent version 1.4 and 2.0 influence libpcap events?

I'm using libpcap and libevent in a program.

the related source codes are:
const u_int16_t RELAY_PORT = 8000;

pcap_t *create_pcap(const void *dev, pcap_style_t style)
        pcap_t *handle;                 /* Session handle */
    struct bpf_program fp;          /* The compiled filter */
        bpf_u_int32 mask;               /* The netmask */
        bpf_u_int32 net;                /* The IP subnet*/
        const struct pcap_pkthdr* pcap_header;   /* A pointer to pcap_pkthdr structure */
        const u_char *pcap_packet;           /* The captured packet */ 

char interface[20];
        strcpy(interface, dev);

/* Find the properties for the network interface */
if (pcap_lookupnet(interface, &net, &mask, errbuf) == -1) {
fprintf(stderr, "Pcap counldn't get netmask for device %s: %s\n", interface, errbuf);
net = 0;
mask = 0;

        handle = pcap_open_live(interface, BUFSIZ, 0, 0, errbuf);
        if (handle == NULL) {
fprintf(stderr, "Pcap open live capture failure: %s\n", errbuf);

sprintf(filter_exp, "tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack) && src port %d || dst port %d", RELAY_PORT, RELAY_PORT);

        /* Compile and apply the filter */
        if (pcap_compile(handle, &fp, filter_exp, 0, mask) == -1) {
fprintf(stderr, "Pcap parse filter failure: %s\n", pcap_geterr(handle));

        if (pcap_setfilter(handle, &fp) == -1) {
fprintf(stderr, "Pcap couldn't install filter: %s\n", pcap_geterr(handle));
if(style == NONBLOCKING){
if(pcap_setnonblock(handle, 1, errbuf) == -1){
         fprintf(stderr, "Pcap set non-blocking fails: %s\n", errbuf);
return handle;


void on_capture(int pcapfd, short op, void *arg)
    int res;
#ifdef DEBUG
printf("on capture \n");
pcap_t *handle;
handle = (pcap_t *)arg;
fqueue_t* pkt_queue;

/* put all packets in the buffer into the packet FIFO queue
 * and then process these packets 
 * */
pkt_queue = init_fqueue();
res = pcap_dispatch(handle, -1, collect_pkt, (u_char *)pkt_queue);
#ifdef DEBUG
printf("pcap_dispatch() returns %d\n", res);
if(!res) return;


int pcapfd;
pcap_t *pcap_handle;
struct event  pcap_ev;

pcap_handle = create_pcap("eth0", NONBLOCKING);  
pcapfd = pcap_get_selectable_fd(pcap_handle);
perror("pcap_get_selectable_fd() failed!\n");

if (setnonblock(pcapfd) == -1) return -1;

base = event_init();

event_set(&pcap_ev, pcapfd, EV_READ|EV_PERSIST, on_capture, pcap_handle);
event_base_set(base, &pcap_ev);
if(event_add(&pcap_ev, NULL) == -1){
    perror("event_add() failed for pcap_ev!\n");

I also register an TCP listening event on event_base( two events: on_accept and on_recv.)

then I run the program on host A and send packets from host B, meanwhile I use a tcpdump to capture packets on A  (tcpdump -i eth0  port 8000 )
For comparison, I have two laptops which acts as A, I tried the program (compile and then run) on these two laptops, one with Fedora (fedora release 18) and one with Ubuntu (Ubuntu 14.04.2 LTS)

on ubuntu events are invoked in the following order 

on capture 
pcap_dispatch() returns 0
on capture 
pcap_dispatch() returns 0
on accept 
on recv 

it is strange that the pcap_dispatch returns 0 twice. My expectation is that the when on_capture event is triggered, pcap_dispatch will catch TCP SYN packets before on_accept event is triggered. But I don't know why the on_capture events are invoked twice and pcap_dispatch()  returns 0.

on Fedora, the program works as expected, the pcap_dispatch() can capture packets the first time it is invoked before on_accept event

I use ldd to check the libraries of this program on each laptop.

     $ldd relay 
linux-vdso.so.1 =>  (0x00007fff1d1ad000)
libevent-1.4.so.2 => /lib/libevent-1.4.so.2 (0x00007faca467d000)
libpcap.so.1 => /lib64/libpcap.so.1 (0x00000035b4a00000)
libc.so.6 => /lib64/libc.so.6 (0x00000035b0a00000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00000035cea00000)
librt.so.1 => /lib64/librt.so.1 (0x00000035b1a00000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00000035b2e00000)
/lib64/ld-linux-x86-64.so.2 (0x00000035b0200000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000035b1600000)


      $ ldd relay 
linux-vdso.so.1 =>  (0x00007ffd08bc5000)
libevent-2.0.so.5 => /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5 (0x00007eff35f81000)
libpcap.so.0.8 => /usr/lib/x86_64-linux-gnu/libpcap.so.0.8 (0x00007eff35d43000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007eff3597e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007eff35760000)
/lib64/ld-linux-x86-64.so.2 (0x00007eff361c5000)

indeed, both libpcap and libevent versions are different.
what are potential problems for my program when it runs on ubuntu? how can fix the unexpected problems on ubuntu?
thank you!
Sanchayan Maity | 5 Oct 19:13 2015

Request for comments on correct use of libevent


I am writing a simple DHT application and using libevent in my
application. The libevent version is 2.0 which is installed by
default on my Arch Linux setup.

After some searching I found an example to use libevent in a
multi-threaded setup.

The above code runs one event base in its own separate thread and
uses a threaded workqueue model to service requests on incoming

I have taken that sample code and modified it for my own purposes.
While my application is functional when I deploy eight of them in
my setup and then check for the basic functionality, while trying
to run multiple operations from multiple application nodes I get
some messages which I do not fully comprehend at the moment.

They are as follows:
1. Epoll %s(%d) on fd %d failed.  Old events were %d; read change was %d (%s); write change was %d (%s); close
change was %d (%s)

Which seems to be printed from epoll.c by event warn mechanism

2. Too many open files

3. One more which I failed to note and was related to EPOLL MOD

I know perhaps this is too much to ask, but can someone have a
look at the code and tell me things I am doing wrong. I have gone
through the libevent documentation online but I am not sure if I
am doing things the right way at the moment.

The peer part of dht I try to make synchronous by trying to break
the event base loop with event loopbreak call in the read cb however
sometimes if the callback never gets called which happens, the peer
part of the DHT is just stuck, so to circumvent this I use a timeout.

The code is attached. I have tried to keep it clean. I am no networking
or socket expert, appreciate any comments or feedback.

Thanks & Regards,
Sanchayan Maity.

Attachment (server.c): text/x-c, 29 KiB
Lei Kong | 25 Sep 04:57 2015

Dynamically adding and removing evconnlistener

I am trying to share event loop among multiple listeners instead of blocking one thread per listener.

Things work fine if I add all my evconnlistener instances before starting the event loop, but only one listener works if I add them after starting event loop (event loop runs in a background thread). Can I dynamically add and remove evconnlistener instances like this?

juan.fernandez | 4 Sep 13:19 2015

evdns doesn't load hosts file on windows



This code skips loading the hosts file when the call to getnetworkparams succeds.

Doesn’t look right to me…






evdns_base_config_windows_nameservers(struct evdns_base *base)


            int r;

            char *fname;

            if (base == NULL)

                         base = current_base;

            if (base == NULL)

                         return -1;


            if (load_nameservers_with_getnetworkparams(base) == 0)            {


                         return 0;


            r = load_nameservers_from_registry(base);


            fname = evdns_get_default_hosts_filename();

            evdns_base_load_hosts(base, fname);