X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=9b91e0371254e67044a8138424334a21aea4b88c;hp=d6b5b5b8b783446ce08e87972b34430b9bf4e547;hb=528865024d7fdb484b2903e2205b8d00fb0550ef;hpb=a31f0050d6f82fdfec7218dfbe86f777777e3029;ds=sidebyside diff --git a/server.cpp b/server.cpp index d6b5b5b..9b91e03 100644 --- a/server.cpp +++ b/server.cpp @@ -107,7 +107,23 @@ void Server::set_header(const string &stream_id, const string &header) void Server::add_data(const string &stream_id, const char *data, size_t bytes) { - // TODO + MutexLock lock(&mutex); + assert(streams.count(stream_id) != 0); + Stream *stream = &streams[stream_id]; + size_t pos = stream->data_size % BACKLOG_SIZE; + stream->data_size += bytes; + + if (pos + bytes > BACKLOG_SIZE) { + size_t to_copy = BACKLOG_SIZE - pos; + memcpy(stream->data + pos, data, to_copy); + data += to_copy; + bytes -= to_copy; + pos = 0; + } + + memcpy(stream->data + pos, data, bytes); + + // TODO: wake up clients } void Server::process_client(Client *client) @@ -216,6 +232,9 @@ void Server::process_client(Client *client) return; } client->bytes_sent += ret; + + // TODO: put clients to sleep + break; } default: