On Sat, Apr 20, 2013 at 3:36 PM, Jan Danielsson <[email protected]> wrote: > Hello, > > I'm doing this (roughly): > > --------------- > udp_sock = create_udo4_any_socket("7777"); > evutil_make_socket_nonblocking(udp_sock); > udp_event = event_new(base, udp_sock, EV_READ|EV_WRITE|EV_PERSIST, > proc_udp_packet, (void*)base); > event_add(udp_event, NULL); > --------------- > > But I want to disable, and later re-enable, EV_WRITE in the callback > function (well, in other functions as well, but I'm guessing the method > would be the same regardless). How is this done?
The easiest approach is to construct two separate events: one with EV_WRITE and one with EV_READ, and then use event_del() to disable the write event and event_add() to re-enable it again. You can also use event_assign() to change the setup of the event, replacing EV_READ|EV_WRITE with EV_READ, but you need to be careful: it is illegal (and will cause undefined behavior) to call event_assign() on a currently pending or active event. So you would need to event_del() the event, event_assign() it, and event_add() it again. There are probably other good approaches too. best wishes, -- Nick *********************************************************************** To unsubscribe, send an e-mail to [email protected] with unsubscribe libevent-users in the body.
