Do I need to unregister fd from epoll/kqueue when closing socket?

470 Views Asked by At

Is it true that if I close a socket its fd is auto purged from epoll and/or kqueue?
If so, does it means there is no need to manually unregister the fd when closing fd?

Actually I'm using Tornado, any advice on that would also be appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

In Tornado, you must call IOLoop.remove_handler before closing the socket. Epoll and kqueue will internally discover automatically that the socket has been closed, but the IOLoop itself still has some state (a mapping from file descriptors to handler functions) that needs to be cleaned up.