if I add an event for a specific socket to event loop, for example, a TCP connection socket. then it may happen that the socket is closed, then how will libevent act? can it detect this?
thanks!
if I add an event for a specific socket to event loop, for example, a TCP connection socket. then it may happen that the socket is closed, then how will libevent act? can it detect this?
thanks!
EDIT: I think I misinterpreted your question at first.
As per the documentation you can use the event_new()
and event_add()
calls to register interest in a socket. Make sure you specify EV_READ
since you are interested in when the socket is closed.
Remember that there is no difference in file descriptor readiness between data available for reading and a closed socket. Normally you must read the socket to find out which condition is true, but if you don't want to read the socket then you can look here for a hint.
Using a file descriptor after it has been closed is never defined and can always lead to undefined results. This is not specific to libevent. Before you close a file descriptor, you must make sure that no other thread in your program is using it, and you must make sure that no other part of your program is going to try using it in the future. That means unregistering the file descriptor from libevent at the same time that you close it.