[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] How to reference event_base in other parts of code?



Hello  All,

I am testing libevent with libcurl using this example 
https://github.com/curl/curl/blob/master/docs/examples/hiperfifo.c

I have integrated the example in my application and it works perfectly as it is. It asks me to put some url in a fifo and after that it gets the url data. All events fire perfectly.

But the example creates a new event base to run the curl stuff 
g.evbase = event_base_new();  // line 435 

Since my application already has an event_base (which is already handling some other read/write events and works fine), I decided to change one line in the example code to use my own event base.

        g.evbase = get_event_base(); //where get_event_base()  returns the base im already using
        init_fifo(&g);
        g.multi = curl_multi_init();
        evtimer_assign(&g.timer_event, g.evbase, timer_cb, &g);

        /* setup the generic multi interface options we want */
        curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
        curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
        curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
        curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);

        /* we don't call any curl_multi_socket*() function yet as we have no handles
           added! */

//also commented out the following portion in the original example
/*
        event_base_dispatch(g.evbase);
        clean_fifo(&g);
        event_del(&g.timer_event);
        event_base_free(g.evbase);
        curl_multi_cleanup(g.multi);
*/

After making this one change when I try to enter some url in the fifo my application segs fault.
The gdb trace shows

Thread 2 "myapp" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6055700 (LWP 25192)]
0x00007ffff781f7c3 in evmap_io_active_ () from /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
(gdb) bt
#0  0x00007ffff781f7c3 in evmap_io_active_ () from /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
#1  0x00007ffff7826928 in ?? () from /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
#2  0x00007ffff781c6f4 in event_base_loop () from /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6
#3  0x00005555555630f3 in my_loop ()
#4  0x00007ffff7a3e669 in start_thread (arg=<optimised out>) at pthread_create.c:479
#5  0x00007ffff752d323 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Just to point out that my app has two threads but all the events and the event_base related stuff are only in one thread.