-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Hi
I've faced to the problem with Poco::Socket::select() method that throws Poco::IOException with error code 22 (EINVAL). After debugging session I've found exact line of code where this exception happens:
File "Net/src/Socket.cpp" Line 155 (1.7.5 version):
epollSize = eventLast - eventsIn;
epollfd = epoll_create(epollSize); // Problem is here when epollSize == 0
if (epollfd < 0)
{
char buf[1024];
strerror_r(errno, buf, sizeof(buf));
SocketImpl::error(std::string("Can't create epoll queue: ") + buf);
}
According to the manual (http://man7.org/linux/man-pages/man2/epoll_create.2.html) 👍
In the initial epoll_create() implementation, the size argument
informed the kernel of the number of file descriptors that the caller
expected to add to the epoll instance. The kernel used this
information as a hint for the amount of space to initially allocate
in internal data structures describing events. (If necessary, the
kernel would allocate more space if the caller's usage exceeded the
hint given in size.) **Nowadays, this hint is no longer required** (the
kernel dynamically sizes the required data structures without needing
the hint), **but size must still be greater than zero**, in order to
ensure backward compatibility when new epoll applications are run on
older kernels.
Maybe it will be better to check size argument and always pass something greater than zero to epoll_create() ? Thanks.
P.S. There is another minor bug with strerror_r function. It has different behaviour and not always changes buf variable but returns char* to the static string. In this case std::string("Can't create epoll queue: ") + buf results in text with random garbage at the end.
Reactions are currently unavailable