X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=35cb9d6bce869b354f73b96f1824e004cf1835ec;hp=52f26db30b8b23598767d3182c18a3e441ee708d;hb=7ec54788f88dde7b083ba6cfd30732b32295b54a;hpb=a3df546ba8ea6fde76bcad14cef5396c024b24be diff --git a/server.cpp b/server.cpp index 52f26db..35cb9d6 100644 --- a/server.cpp +++ b/server.cpp @@ -435,7 +435,6 @@ void Server::set_hls_backlog_margin(int stream_index, size_t hls_backlog_margin) { lock_guard lock(mu); assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); - assert(hls_backlog_margin >= 0); assert(hls_backlog_margin < streams[stream_index]->backlog_size); streams[stream_index]->hls_backlog_margin = hls_backlog_margin; } @@ -459,26 +458,14 @@ void Server::set_header(int stream_index, const string &http_header, const strin { lock_guard lock(mu); assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); - Stream *stream = streams[stream_index].get(); - stream->http_header = http_header; - - if (stream_header != stream->stream_header) { - // We cannot start at any of the older starting points anymore, - // since they'd get the wrong header for the stream (not to mention - // that a changed header probably means the stream restarted, - // which means any client starting on the old one would probably - // stop playing properly at the change point). Next block - // should be a suitable starting point (if not, something is - // pretty strange), so it will fill up again soon enough. - stream->suitable_starting_points.clear(); - - if (!stream->fragments.empty()) { - stream->fragments.clear(); - ++stream->discontinuity_counter; - stream->clear_hls_playlist_cache(); - } - } - stream->stream_header = stream_header; + streams[stream_index]->set_header(http_header, stream_header); +} + +void Server::set_unavailable(int stream_index) +{ + lock_guard lock(mu); + assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); + streams[stream_index]->set_unavailable(); } void Server::set_pacing_rate(int stream_index, uint32_t pacing_rate) @@ -650,7 +637,7 @@ sending_header_or_short_response_again: } else if (client->stream_pos_end != Client::STREAM_POS_NO_END) { // We're sending a fragment, and should have all of it, // so start sending right away. - assert(client->stream_pos >= 0); + assert(ssize_t(client->stream_pos) >= 0); client->state = Client::SENDING_DATA; goto sending_data; } else if (stream->prebuffering_bytes == 0) { @@ -1117,9 +1104,6 @@ int Server::parse_request(Client *client) } Stream *stream = client->stream; - if (stream->http_header.empty()) { - return 503; // Service unavailable. - } if (client->serving_hls_playlist) { if (stream->encoding == Stream::STREAM_ENCODING_METACUBE) { @@ -1131,6 +1115,10 @@ int Server::parse_request(Client *client) } if (client->stream_pos_end == Client::STREAM_POS_NO_END) { + if (stream->unavailable) { + return 503; // Service unavailable. + } + // This stream won't end, so we don't have a content-length, // and can just as well tell the client it's Connection: close // (otherwise, we'd have to implement chunking TE for no good reason).