#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;
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.
// 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);