X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.h;h=8d5261f6ca9b42fb84bab11776486cd44a67f125;hp=79794939280cf315359f602344d3681d287054e0;hb=f87901a18647fb66d766a1db55589fc753f46008;hpb=462cb16514a2b691ae4d4b76125b42fda83df712 diff --git a/server.h b/server.h index 7979493..8d5261f 100644 --- a/server.h +++ b/server.h @@ -9,6 +9,8 @@ #include #include +#include "thread.h" + #define BACKLOG_SIZE 1048576 #define EPOLL_MAX_EVENTS 8192 #define EPOLL_TIMEOUT_MS 20 @@ -117,17 +119,11 @@ private: Stream(const Stream& other); }; -class Server { +class Server : public Thread { public: Server(); ~Server(); - // Start a new thread that handles clients. - void run(); - - // Stop the thread. - void stop(); - // Get the list of all currently connected clients. std::vector get_client_stats() const; @@ -153,8 +149,6 @@ public: void add_stream_from_serialized(const StreamProto &stream); private: - pthread_t worker_thread; - // Mutex protecting queued_data only. Note that if you want to hold both this // and below, you will need to take before this one. mutable pthread_mutex_t queued_data_mutex; @@ -175,9 +169,6 @@ private: // All variables below this line are protected by the mutex. mutable pthread_mutex_t mutex; - // If the thread should stop or not. - bool should_stop; - // Map from stream ID to stream. std::map streams; @@ -188,11 +179,8 @@ private: int epoll_fd; epoll_event events[EPOLL_MAX_EVENTS]; - // Recover the this pointer, and call do_work(). - static void *do_work_thunk(void *arg); - // The actual worker thread. - void do_work(); + virtual void do_work(); // Process a client; read and write data as far as we can. // After this call, one of these four is true: