Fix an off-by-one issue in the POLL code

This commit is contained in:
louiz’
2016-10-12 21:00:05 +02:00
parent c54f28d29d
commit 5f2e4820df
+2 -2
View File
@@ -95,7 +95,7 @@ void Poller::remove_socket_handler(const socket_t socket)
void Poller::watch_send_events(SocketHandler* socket_handler) void Poller::watch_send_events(SocketHandler* socket_handler)
{ {
#if POLLER == POLL #if POLLER == POLL
for (size_t i = 0; i <= this->nfds; ++i) for (size_t i = 0; i < this->nfds; ++i)
{ {
if (this->fds[i].fd == socket_handler->get_socket()) if (this->fds[i].fd == socket_handler->get_socket())
{ {
@@ -171,7 +171,7 @@ int Poller::poll(const std::chrono::milliseconds& timeout)
// We cannot possibly have more ready events than the number of fds we are // We cannot possibly have more ready events than the number of fds we are
// watching // watching
assert(static_cast<unsigned int>(nb_events) <= this->nfds); assert(static_cast<unsigned int>(nb_events) <= this->nfds);
for (size_t i = 0; i <= this->nfds && nb_events != 0; ++i) for (size_t i = 0; i < this->nfds && nb_events != 0; ++i)
{ {
auto socket_handler = this->socket_handlers.at(this->fds[i].fd); auto socket_handler = this->socket_handlers.at(this->fds[i].fd);
if (this->fds[i].revents == 0) if (this->fds[i].revents == 0)