I have some code that when run on a virtual machine is misbehaving for some reason.
The order of initialization is:
s_listen = socket(...)
bind(s_listen, ...)
epoll_ctl(epfd, EPOLL_CTL_ADD, s_listen, ...)
listen(s_listen, SOMAXCONN)
There is an event loop/thread running and processing events on the epoll file descriptor before bind is even called.
That event loop gets an EPOLLHUP before the call to listen() on the newly created s_listen socket.
So my question is, why am I getting the EPOLLHUP event on a brand new socket?
The error goes away when I put the epoll_ctl after call to listen(), however will that cause some potential connection events to be missed should they come in before the socket is added to epoll?
accept
,connect
orlisten
). Are you sure that adding a non-initialized socket to an epoll set is valid?