void EventLoop::eventLoop() {
while(running) {
int socketAcceptFD = socketHandler.acceptNewClient();
if(socketAcceptFD != -1) {
addClient(socketAcceptFD);
} else if(errno != EAGAIN && errno != EWOULDBLOCK) {
running = false;
return;
}
if(poll(pollFDs.data(), pollFDs.size(), 10) <= 0) continue;
std::vector<pollfd> pollFDs = this->pollFDs;
for(pollfd &pollFD : pollFDs) {
auto clientIter = std::find_if(clients.begin(), clients.end(), [pollFD](std::unique_ptr<Client> &client) {
return client->fd == pollFD.fd;
});
if(clientIter == clients.end()) {
//Non-stardust client with fd in clientPollFDs like wayland for example
continue;
}
if(pollFD.revents &= POLLERR | POLLHUP | POLLNVAL) {
removeClient(pollFD.fd);
continue;
}
if(pollFD.revents &= POLLIN) {
Client *const client = clientIter->get();
client->messenger.dispatch();
}
}
}
}
void EventLoop::eventLoop() {
while(running) {
int socketAcceptFD = socketHandler.acceptNewClient();
if(socketAcceptFD != -1) {
addClient(socketAcceptFD);
} else if(errno != EAGAIN && errno != EWOULDBLOCK) {
running = false;
return;
}
if(poll(pollFDs.data(), pollFDs.size(), 10) <= 0) continue;
std::vector<pollfd> pollFDs = this->pollFDs;
for(pollfd &pollFD : pollFDs) {
auto clientIter = std::find_if(clients.begin(), clients.end(), [pollFD](std::unique_ptr<Client> &client) {
return client->fd == pollFD.fd;
});
if(clientIter == clients.end()) {
//Non-stardust client with fd in clientPollFDs like wayland for example
continue;
}
if(pollFD.revents &= POLLERR | POLLHUP | POLLNVAL) {
removeClient(pollFD.fd);
continue;
}
if(pollFD.revents &= POLLIN) {
Client *const client = clientIter->get();
client->messenger.dispatch();
}
}
}
}