讨论epoll方法中epoll_ctl关于取消注册相关的话题

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

首先,如果文件描述符sock_fd,只有一份拷贝,那么close(sock_fd)后,epoll中注册的相关sock_fd,就会自动被清理,那么请问epoll_ctl中参数EPOLL_CTL_DEL有什么作用呢?下面详细描述(源地址:http://stackoverflow.com/questions/8707601/is-it-necessary-to-deregister-a-socket-from-epoll-before-closing-it)

Q6 Will closing a file descriptor cause it to be removed from all epoll sets automatically?

A6 Yes, but be aware of the following point. A file descriptor is a reference to an open file description (seeopen(2)). Whenever a descriptor is duplicated viadup(2),dup2(2),fcntl(2)F_DUPFD, orfork(2), a new file descriptor referring to the same open file description is created. An open file description continues to exist until all file descriptors referring to it have been closed. A file descriptor is removed from anepollset only after all the file descriptors referring to the underlying open file description have been closed (or before if the descriptor is explicitly removed usingepoll_ctl(2)EPOLL_CTL_DEL). This means that even after a file descriptor that is part of anepollset has been closed, events may be reported for that file descriptor if other file descriptors referring to the same underlying file description remain open.


转载于:https://my.oschina.net/u/931988/blog/129076

你可能感兴趣的:(epoll,python)