pending_data.clear();
has_metacube_header = false;
for (int stream_index : stream_indices) {
- servers->set_header(stream_index, "", "");
+ // Don't zero out the header; it might still be of use to HLS clients.
+ servers->set_unavailable(stream_index);
}
{
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->set_header(http_header, stream_header);
}
+
+void Server::set_unavailable(int stream_index)
+{
+ lock_guard<mutex> 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)
{
}
if (client->stream_pos_end == Client::STREAM_POS_NO_END) {
- if (stream->http_header.empty()) {
+ if (stream->unavailable) {
return 503; // Service unavailable.
}
const std::string &http_header,
const std::string &stream_header);
+ // Sets the given stream as unavailable (will always return 503 to new clients).
+ void set_unavailable(int stream_index);
+
// Set that the given stream should use the given max pacing rate from now on.
// NOTE: This should be set before any clients are connected!
void set_pacing_rate(int stream_index, uint32_t pacing_rate);
}
}
+void ServerPool::set_unavailable(int stream_index)
+{
+ assert(stream_index >= 0 && stream_index < ssize_t(num_http_streams));
+
+ for (int i = 0; i < num_servers; ++i) {
+ servers[i].set_unavailable(stream_index);
+ }
+}
+
void ServerPool::add_gen204(const std::string &url, const std::string &allow_origin)
{
for (int i = 0; i < num_servers; ++i) {
const std::string &stream_header);
void add_data(int stream_index, const char *data, size_t bytes, uint16_t metacube_flags, const RationalPTS &pts);
+ // Sets the given stream as unavailable on all the servers.
+ void set_unavailable(int stream_index);
+
// Sets the max pacing rate for all the servers.
void set_pacing_rate(int stream_index, uint32_t pacing_rate);
// Corresponds to struct Stream.
message StreamProto {
+ optional bool unavailable = 14 [default=false];
optional bytes http_header = 6;
optional bytes stream_header = 7;
repeated int32 data_fds = 8;
Stream::Stream(const StreamProto &serialized, int data_fd)
: url(serialized.url()),
+ unavailable(serialized.unavailable()),
http_header(serialized.http_header()),
stream_header(serialized.stream_header()),
encoding(Stream::STREAM_ENCODING_RAW), // Will be changed later.
StreamProto Stream::serialize()
{
StreamProto serialized;
+ serialized.set_unavailable(unavailable);
serialized.set_http_header(http_header);
serialized.set_stream_header(stream_header);
serialized.add_data_fds(data_fd);
void Stream::set_header(const std::string &new_http_header, const std::string &new_stream_header)
{
+ unavailable = false;
http_header = new_http_header;
if (new_stream_header == stream_header) {
return;
void set_backlog_size(size_t new_size);
// You should hold the owning Server's <mutex>, since it calls add_data_raw().
+ // Sets unavailable to false.
void set_header(const std::string &new_http_header, const std::string &new_stream_header);
+ void set_unavailable() {
+ unavailable = true;
+ }
+
// Mutex protecting <queued_data> and <queued_data_last_starting_point>.
// Note that if you want to hold both this and the owning server's
// <mutex> you will need to take <mutex> before this one.
std::string url;
+ // If true, the backend is not completely connected, and thus, we cannot serve
+ // clients (except for historic HLS fragments).
+ bool unavailable = true;
+
// The HTTP response header, without the trailing double newline.
std::string http_header;