Yes, I just found out that I need to call event_add before start the
message pump.

Thanks.
Kun

On Tue, Aug 30, 2011 at 10:50 AM, Nick Mathewson <ni...@freehaven.net> wrote:
> On Tue, Aug 30, 2011 at 1:46 PM, Kun Xi <ku...@kunxi.org> wrote:
>> Hello,
>>
>> I just wondered whether libevent event loop can handle the SIGTERM and
>> SIGQUIT appropriately.  Here is the code snippet I am trying to exit
>> the message loop gracefully and brutally:
>>
>> static void quick_shutdown(evutil_socket_t _, short what, void* ctx) {
>>    struct event_base *evb = (struct event_base*) ctx;
>>    event_base_loopbreak(evb);
>> }
>>
>> static void graceful_shutdown(evutil_socket_t _, short what, void* ctx) {
>>    struct event_base *evb = (struct event_base*) ctx;
>>    event_base_loopexit(evb, NULL);
>> }
>>
>> // main()
>>    /* signal handling */
>>    struct event *quit = evsignal_new(base, SIGQUIT, graceful_shutdown, base);
>>    struct event *term = evsignal_new(base, SIGTERM, quick_shutdown, base);
>>
>>    /* message loop */
>>    event_base_dispatch(base);
>>
>>    /* cleanup the mess */
>>    event_free(quit);
>>    event_free(term);
>>    event_base_free(base);
>>    return 0;
>>
>> I expect that the process exits the message loop with kill -15 or kill
>> -3. But it never happens. I wonder whether something wrong with my
>> code, or we should not use libevent to handle SIGQUIT and SIGTERM.
>
> Looks like you never called event_add() on those events.
> evsignal_new(), like event_new(), only creates a new event: you need
> to use event_add() to make the base start watching for it.
>
> cheers,
> --
> Nick
> ***********************************************************************
> To unsubscribe, send an e-mail to majord...@freehaven.net with
> unsubscribe libevent-users    in the body.
>
***********************************************************************
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-users    in the body.

Reply via email to