how to use epoll with data->ptr, instead of data.fd?
Asked Answered
U

1

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

Urissa answered 25/12, 2012 at 6:52 Comment(1)
Here's another related question that might help better: https://mcmap.net/q/811963/-about-epoll_ctlAggie
A
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.

Aggie answered 25/12, 2012 at 7:12 Comment(2)
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?Urissa
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.Aggie

© 2022 - 2024 — McMap. All rights reserved.