7

I'm writing an application using epoll and large amount of fd's. in order to improve the searches of fd to application relevant DB, I want to pass to epoll application info, such as index in DB array. I thought of using the data->ptr (epoll_data_t --> *ptr), as far as I understood, I can give pointer that holds the fd and private information from the application layer, but couldn't found any documents or examples.

I found this post, which seems to be relevant, but there is no implementation example... How to use epoll_event data.ptr

Thanks

Community
  • 1
  • 1
user1927740
  • 73
  • 1
  • 4
  • 1
    Here's another related question that might help better: http://stackoverflow.com/questions/9325748/about-epoll-ctl – Barmar Dec 25 '12 at 07:10

1 Answers1

14

You can put whatever you want in data. It's not used by epoll itself, it just returns it when the event occurs on the fd specified in the argument list.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Hi Barmer - Thanks for your comment. I'm missing out something here, the epoll data struct is UNION, looks like that: typedef union epoll_data { void *ptr; int fd; uint32_t u32; uint64_t u64; } epoll_data_t; --> meaning that if I'm writing something to *ptr, and then writing to the fd, it will overwrite the *ptr value (it's union...) what is the correct way to write to the *ptr, and keep the fd? – user1927740 Dec 26 '12 at 09:09
  • 2
    You don't need to keep the fd in `epoll_data`. The fd that's being polled is the third argument to `epoll_ctl()`, not the one in the structure. If _you_ need to know the fd, put it in the structure that `ptr` points to. – Barmar Dec 26 '12 at 13:40