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

[Libevent-users] Help with progress thread



Hi folks

I'm running into a problem that probably results from my ignorance. So I figured I would ask if someone can tell me what I'm doing wrong.

I have a thread that loops the event library with the following call:

        events += event_loop(mca_oob_tcp_component.event_base, EVLOOP_ONCE);

In another thread, I create and add an event that is supposed to occur when a file descriptor is ready for "write":

         event_set(mca_oob_tcp_component.event_base,
                       &peer->peer_send_event,
                       peer->peer_sd,
                       EV_WRITE|EV_PERSIST,
                       mca_oob_tcp_peer_send_handler,
                       peer);
         event_add(&peer->peer_send_event, 0);

Note that the event_set and event_add can (and in this case, probably do) occur while I am in the event_loop function.

What I find is that this event never gets fired. However, events that are set and added -before- going into the loop do fire.

So my question is: given that this is a dynamic system, how do I get the event_loop to "see" new events? I want to block in the loop, so I don't really want to set NONBLOCK if I can avoid it (otherwise, I would have to add another blocking call somewhere to keep the thread from endlessly cycling).

The only thing I could think of was to (a) create an event looking at a pipe, and then (b) every time I define a new event, send a byte down the pipe to break myself out of the loop, thus allowing the event_loop function to "see" the new event.

Any cleaner alternatives? I figure this -must- be a common problem...
Ralph

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.