X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=6b92fc6af5eb6eec6fa9983a587681dfc2e14623;hp=f06685ab02224ea654b85d82f09d35a5dc456a5c;hb=fbfb955ee7233030357ec32c0d613f9279700d70;hpb=c2c9f6441f9ae8091a39aea0340417d5915e1ac9 diff --git a/server.cpp b/server.cpp index f06685a..6b92fc6 100644 --- a/server.cpp +++ b/server.cpp @@ -196,11 +196,11 @@ void Server::do_work() for (map::iterator stream_it = streams.begin(); stream_it != streams.end(); ++stream_it) { - Stream *stream = stream_it->second; - for (size_t i = 0; i < stream->to_process.size(); ++i) { - process_client(stream->to_process[i]); + vector to_process; + swap(stream_it->second->to_process, to_process); + for (size_t i = 0; i < to_process.size(); ++i) { + process_client(to_process[i]); } - stream->to_process.clear(); } } } @@ -575,6 +575,13 @@ void Server::construct_error(Client *client, int error_code) exit(1); } } + +template +void delete_from(vector *v, T elem) +{ + typename vector::iterator new_end = remove(v->begin(), v->end(), elem); + v->erase(new_end, v->end()); +} void Server::close_client(Client *client) { @@ -585,12 +592,8 @@ void Server::close_client(Client *client) // This client could be sleeping, so we'll need to fix that. (Argh, O(n).) if (client->stream != NULL) { - vector::iterator new_end = - remove(client->stream->sleeping_clients.begin(), - client->stream->sleeping_clients.end(), - client); - client->stream->sleeping_clients.erase( - new_end, client->stream->sleeping_clients.end()); + delete_from(&client->stream->sleeping_clients, client); + delete_from(&client->stream->to_process, client); } // Bye-bye!