9 #define BACKLOG_SIZE 1048576
12 enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA };
15 // The HTTP request, as sent by the client. If we are in READING_REQUEST,
16 // this might not be finished.
17 std::string client_request;
20 // What stream we're connecting to; parsed from client_request.
21 // Not relevant for READING_REQUEST.
25 // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER.
26 size_t header_bytes_sent;
28 // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
33 // The HTTP response header, plus the video stream header (if any).
36 // The stream data itself, stored in a circular buffer.
37 char data[BACKLOG_SIZE];
39 // How many bytes <data> contains. Can very well be larger than BACKLOG_SIZE,
40 // since the buffer wraps.
48 // Start a new thread that handles clients.
50 void add_client(int sock);
51 void add_stream(const std::string &stream_id);
52 void set_header(const std::string &stream_id, const std::string &header);
53 void add_data(const std::string &stream_id, const char *data, size_t bytes);
56 pthread_mutex_t mutex;
58 // Map from stream ID to stream.
59 std::map<std::string, Stream> streams;
61 // Map from file descriptor to client.
62 std::map<int, Client> clients;
66 // Recover the this pointer, and call do_work().
67 static void *do_work_thunk(void *arg);
69 // The actual worker thread.
73 #endif // !defined(_SERVER_H)