Question

I have some questions on libevent event priority

1 what is the priority number range?

2 in the mannual, it says By default, libevent assigns the middle priority to all events unless their priority is explicitly set. so what is the exact default priority number?

3 when priority is higher, the number is smaller or larger?

4 There are two functions which are related to event priority in libevent. event_priority_init() and event_priority_set, what are the differences between them?

5 what are return values for event_priority_set(struct event *ev, int pri)? I notice an article says something like: when an event is ready, it can't be set and calling of this function returns -1. I really don't understand what does this mean? can anyone explain a bit? thanks!

6 can I modify event priority after it is registered. For example, at the beginning, I set the priority to 10, later I set it to 5, then I set it to 10, blalba

BTW: currently, my base = event_init(); event_base_priority_init(base, 4);

event_set(ev, sockfd, EV_READ, callback, arg);
event_base_set(base, ev);
event_add(ev, NULL);
event_priority_set(&ev, 2);

 .....
 // set and add some other events
 ....

event_base_dispatch(base);

it runs without errors, but I don't know whether the place of event_priority_set(&ev, 2) is correct or not, so I don't know whether the priority is set or not.

Was it helpful?

Solution

Nothing here you won't find the answer to in the great book written by Nick :

http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html

1/ You set the range by calling event_base_priority_init().

2/ If you don't set the priority, " the default is the number of queues in the event base, divided by 2."

3/ The lower number is the higher priority.

4/ You should use event_base_priority_init() instead of event_priority_init() which is deprecated. event_base_priority_init() set the number of priority for the base, while event_priority_set() set the priority for an event.

5/ You can't use event_priority_set() on an already added to the event loop (event_add()).

6/ You need to remove it from the event loop with event_del() first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top