]> git.sesse.net Git - cubemap/blobdiff - server.h
Implement header sending.
[cubemap] / server.h
index d8b9064f492f2ad12e333747b389bd1093b2564a..f1cc7a0dbfc0d56116739ebccda95829d8cfe577 100644 (file)
--- a/server.h
+++ b/server.h
@@ -6,9 +6,16 @@
 #include <string>
 #include <map>
 
+#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;
 
@@ -16,11 +23,14 @@ struct Client {
        // this might not be finished.
        std::string client_request;
 
-#if 0
        // What stream we're connecting to; parsed from client_request.
        // Not relevant for READING_REQUEST.
-       string stream_id;
-#endif
+       std::string stream_id;
+
+       // The header we want to send. This is nominally a copy of Stream::header,
+       // but since that might change on reconnects etc., we keep a local copy here.
+       // Only relevant for SENDING_HEADER; blank otherwise.
+       std::string header;
 
        // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER.
        size_t header_bytes_sent;
@@ -53,6 +63,15 @@ public:
        void add_data(const std::string &stream_id, const char *data, size_t bytes);
 
 private:
+       void process_client(Client *client);
+
+       // Close a given client socket, and clean up after it.
+       void close_client(Client *client);
+
+       // Parse the HTTP request, construct the header, and set the client into
+       // the SENDING_HEADER state.
+       void parse_request(Client *client);
+
        pthread_mutex_t mutex;
 
        // Map from stream ID to stream.
@@ -61,7 +80,9 @@ private:
        // Map from file descriptor to client.
        std::map<int, Client> 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);