When you add a fd to an epoll set, you can associate some state with it by using 'struct epoll_event.data'. When epoll reports an event on the fd, it, of course, returns the associated data to the user along with the event. This implies that the epoll set is maintaining a mapping between fds and associated state.
Let's say that I am setting epoll_event.data.ptr to some state that I dynamically allocated and at some point in future, I want to remove the fd from the epoll set and consequently free the memory that I set in ptr earlier.
As far as I can tell, there is no programmatic way for me to look up the state associated with a fd in an epoll set to accomplish the above. I am currently maintaining my own mapping between fds and associated state. I understand that maintaining this mapping doesn't require much memory but I still feel like it is not very efficient to maintain the same mapping in two different places.
So my question is: Is there a way to retrieve the state associated with a fd in an epoll set?