if (should_stop) {
return;
}
-
+
for (int i = 0; i < nfds; ++i) {
int fd = events[i].data.fd;
assert(clients.count(fd) != 0);
process_client(client);
}
+
+ for (unsigned i = 0; i < to_process.size(); ++i) {
+ process_client(to_process[i]);
+ }
+ to_process.clear();
}
}
void Server::wake_up_all_clients()
{
- vector<Client *> to_process;
- swap(sleeping_clients, to_process);
- for (unsigned i = 0; i < to_process.size(); ++i) {
- process_client(to_process[i]);
+ if (to_process.empty()) {
+ swap(sleeping_clients, to_process);
+ } else {
+ to_process.insert(to_process.end(), sleeping_clients.begin(), sleeping_clients.end());
+ sleeping_clients.clear();
}
}
// See put_client_to_sleep() and wake_up_all_clients().
std::vector<Client *> sleeping_clients;
+ // Clients that we recently got data for (when they were in
+ // <sleeping_clients>).
+ std::vector<Client *> to_process;
+
// Recover the this pointer, and call do_work().
static void *do_work_thunk(void *arg);