X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.h;h=c44b81ee357b7ed3e2d6cd629d8690b009334ddd;hp=d8b9064f492f2ad12e333747b389bd1093b2564a;hb=cfe0df3728d8155fb03688f6db69e00971e23685;hpb=fcdb2b3926312cbd42e2d45bb4cec8f984fb325c diff --git a/server.h b/server.h index d8b9064..c44b81e 100644 --- a/server.h +++ b/server.h @@ -6,9 +6,16 @@ #include #include +#define NUM_SERVERS 4 #define BACKLOG_SIZE 1048576 +#define EPOLL_MAX_EVENTS 8192 +#define EPOLL_TIMEOUT_MS 20 +#define MAX_CLIENT_REQUEST 16384 struct Client { + // The file descriptor associated with this socket. + int sock; + enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA }; State state; @@ -53,6 +60,9 @@ public: void add_data(const std::string &stream_id, const char *data, size_t bytes); private: + void process_client(Client *client); + void close_client(Client *client); + pthread_mutex_t mutex; // Map from stream ID to stream. @@ -61,7 +71,9 @@ private: // Map from file descriptor to client. std::map clients; + // Used for epoll implementation (obviously). int epoll_fd; + epoll_event events[EPOLL_MAX_EVENTS]; // Recover the this pointer, and call do_work(). static void *do_work_thunk(void *arg);