]> git.sesse.net Git - cubemap/blobdiff - server.h
Change from level-triggered to edge-triggered epoll mode. More than halves CPU usage.
[cubemap] / server.h
index cc1b78dd2a6a95da7fd7e4ec9819714c2170518c..24e2fcbac3a737a91211bed9eea590d9d1c1a86a 100644 (file)
--- a/server.h
+++ b/server.h
@@ -120,7 +120,7 @@ private:
        // Clients that are in SENDING_DATA, but that we don't listen on,
        // because we currently don't have any data for them.
        // See put_client_to_sleep() and wake_up_all_clients().
-       std::vector<int> sleeping_clients;
+       std::vector<Client *> sleeping_clients;
 
        // Recover the this pointer, and call do_work().
        static void *do_work_thunk(void *arg);
@@ -128,6 +128,19 @@ private:
        // The actual worker thread.
        void do_work();
 
+       // Process a client; read and write data as far as we can.
+       // After this call, one of these four is true:
+       //
+       //  1. The socket is closed, and the client deleted.
+       //  2. We are still waiting for more data from the client.
+       //  3. We've sent all the data we have to the client,
+       //     and put it in <sleeping_clients>.
+       //  4. The socket buffer is full (which means we still have
+       //     data outstanding).
+       //
+       // For #2, we listen for EPOLLIN events. For #3 and #4, we listen
+       // for EPOLLOUT in edge-triggered mode; it will never fire for #3,
+       // but it's cheaper than taking it in and out all the time.
        void process_client(Client *client);
 
        // Close a given client socket, and clean up after it.