Question

By using libevent-2.x, there was a option EV_TIMEOUT that labels timeout on specific fd:

event_set(&ev, fd, EV_READ | EV_TIMEOUT, worker, priv_data);

By setting the timeout to 5 minutes, the fd will set to be timeout by server. I need the hint to free the priv_data or do some statistic on server side, is there was a way to find the timeout fd only by setting the EV_TIMEOUT option(e.g., callback)?

Was it helpful?

Solution

I'm not sure if I'm understanding this part of your question "only by setting the EV_TIMEOUT option. The rest of it, I think I am able to answer for you.

There is a way that you can check to see if the timeout event caused the event to return to the callback.

Let's say your callback prototype looks like this

(evutil_socket_t fd, short what, void *arg)

Then you can check for a timeout on the fd by doing: (what&EV_TIMEOUT)

The relevant types are defined in <event2/event.h>.

In case this doesn't answer your question, you can find a lot of relevant info here, for example: http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html

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