From: Steinar H. Gunderson Date: Sun, 28 Apr 2013 16:48:24 +0000 (+0200) Subject: Add a hack for starting at the _start_ of backlog. Useful for fetching samples of... X-Git-Tag: 1.0.0~37^2 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=cabe676b1637ad3d7193d59090f43d271253e81a Add a hack for starting at the _start_ of backlog. Useful for fetching samples of streams crashing VLC after-the-back. --- diff --git a/client.h b/client.h index c73810d..cd909e3 100644 --- a/client.h +++ b/client.h @@ -63,7 +63,10 @@ struct Client { size_t header_or_error_bytes_sent; // Number of bytes we are into the stream (ie., the end of last send). - // Only relevant for SENDING_DATA. + // -1 means we want to send from the end of the backlog (the normal case), + // -2 means we want to send from the _beginning_ of the backlog. + // Once we go into SENDING_DATA, these negative values will be translated + // to real numbers. size_t stream_pos; // Number of bytes we've sent of data. Only relevant for SENDING_DATA. diff --git a/server.cpp b/server.cpp index 1f5477e..7acf501 100644 --- a/server.cpp +++ b/server.cpp @@ -384,7 +384,15 @@ sending_header_or_error_again: // but we'll start sending immediately as we get data. // This is postcondition #3. client->state = Client::SENDING_DATA; - client->stream_pos = client->stream->bytes_received; + if (client->stream_pos == size_t(-2)) { + client->stream_pos = std::min( + client->stream->bytes_received - client->stream->backlog_size, + 0); + } else { + // client->stream_pos should be -1, but it might not be, + // if we have clients from an older version. + client->stream_pos = client->stream->bytes_received; + } client->stream->put_client_to_sleep(client); return; } @@ -476,7 +484,15 @@ int Server::parse_request(Client *client) return 400; // Should maybe be 405 instead? } - map::const_iterator url_map_it = url_map.find(request_tokens[1]); + string url = request_tokens[1]; + if (url.find("?backlog") == url.size() - 8) { + client->stream_pos = -2; + url = url.substr(0, url.size() - 8); + } else { + client->stream_pos = -1; + } + + map::const_iterator url_map_it = url_map.find(url); if (url_map_it == url_map.end()) { return 404; // Not found. }