#include <assert.h>
#include <arpa/inet.h>
#include <curl/curl.h>
+#include <sys/socket.h>
#include <vector>
+#include <string>
+#include <map>
#include "metacube.h"
+#define NUM_SERVERS 4
+#define STREAM_ID "stream"
+#define STREAM_URL "http://gruessi.zrh.sesse.net:4013/"
+#define BACKLOG_SIZE 1048576
+
using namespace std;
+struct Client {
+ enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA };
+ State state;
+
+ // The HTTP request, as sent by the client. If we are in READING_REQUEST,
+ // this might not be finished.
+ string client_request;
+
+#if 0
+ // What stream we're connecting to; parsed from client_request.
+ // Not relevant for READING_REQUEST.
+ string stream_id;
+#endif
+
+ // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER.
+ size_t header_bytes_sent;
+
+ // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
+ size_t bytes_sent;
+};
+
+struct Stream {
+ // The HTTP response header, plus the video stream header (if any).
+ string header;
+
+ // The stream data itself, stored in a circular buffer.
+ char data[BACKLOG_SIZE];
+
+ // How many bytes <data> contains. Can very well be larger than BACKLOG_SIZE,
+ // since the buffer wraps.
+ size_t data_size;
+};
+
+class Server {
+public:
+ void add_socket(int server_sock);
+ void add_stream(const string &stream_id);
+ void set_header(const string &stream_id, const string &header);
+ void add_data(const string &stream_id, const char *data, size_t bytes);
+
+private:
+ map<string, Stream> streams;
+};
+
class Input {
public:
Input();