When closing a client, make sure it is not left in sleeping_clients.
[cubemap] / server.cpp
index da721e780c2149c566ada02fc7ca9d1c942f4602..d894bd14d0a85d05783366fb60f0394fcf7c86dc 100644 (file)
@@ -13,6 +13,7 @@
 #include <vector>
 #include <string>
 #include <map>
+#include <algorithm>
 
 #include "metacube.h"
 #include "server.h"
@@ -284,6 +285,11 @@ void Server::close_client(Client *client)
                perror("epoll_ctl(EPOLL_CTL_DEL)");
                exit(1);
        }
+
+       // This client could be sleeping, so we'll need to fix that. (Argh, O(n).)
+       vector<int>::iterator new_end =
+               remove(sleeping_clients.begin(), sleeping_clients.end(), client->sock);
+       sleeping_clients.erase(new_end, sleeping_clients.end());
        
        // Bye-bye!
        close(client->sock);