Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I register 2 or multiple events for the same socket descriptor on epoll?

for the same socket, I want to register two events: one is EPOLLIN and another is EPOLLOUT|EPOLLET.

so for input, I want it to be level trigger and for output I want it to be edge trigger.

            ev.data.fd=fd;
            ev.events=EPOLLIN;
            epoll_ctl(epfd,EPOLL_CTL_ADD,fd,&ev);
            ev.events=EPOLLOUT|EPOLLET;
            epoll_ctl(epfd,EPOLL_CTL_ADD,fd,&ev);

is it possible or not? are there any problems? thanks!

like image 649
misteryes Avatar asked Sep 05 '25 03:09

misteryes


1 Answers

Here's from epoll(7) Questions and answers section:

Q1 What happens if you register the same file descriptor on an epoll instance twice?

A1 You will probably get EEXIST. However, it is possible to add a duplicate (dup(2), dup2(2), fcntl(2) F_DUPFD) descriptor to the same epoll instance. This can be a useful technique for filtering events, if the duplicate file descriptors are registered with different events masks.

like image 126
Nikolai Fetissov Avatar answered Sep 07 '25 21:09

Nikolai Fetissov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!