]> git.sesse.net Git - cubemap/commitdiff
Fix handling of streams with no data.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Feb 2014 23:25:41 +0000 (00:25 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Feb 2014 23:25:41 +0000 (00:25 +0100)
The original plan here was to let the client hang until we had
some headers to send (ie., first send an empty header and then
0 bytes data, and then send the client back from SENDING_DATA
to SENDING_HEADER as we got data).

However, as time went by, we started inserting stuff in the middle of the
headers ourselves, resulting in us sending pretty much a junk header.
Worse, this would be sent on to other relays, corrupting the version of
the Metacube stream.

Simply return 503 Not Available now instead if the stream is still
starting up; it's pretty much as good, and has fewer edge cases
to worry about.

server.cpp

index ee91ed8449faa1c5c6b6b344dbc733ca000aa6c8..093899939b4d832be6dd28a8a3e8966d46efa650 100644 (file)
@@ -252,19 +252,6 @@ void Server::set_header(int stream_index, const string &http_header, const strin
        assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
        streams[stream_index]->http_header = http_header;
        streams[stream_index]->stream_header = stream_header;
        assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
        streams[stream_index]->http_header = http_header;
        streams[stream_index]->stream_header = stream_header;
-
-       // If there are clients we haven't sent anything to yet, we should give
-       // them the header, so push back into the SENDING_HEADER state.
-       for (map<int, Client>::iterator client_it = clients.begin();
-            client_it != clients.end();
-            ++client_it) {
-               Client *client = &client_it->second;
-               if (client->state == Client::WAITING_FOR_KEYFRAME ||
-                   (client->state == Client::SENDING_DATA &&
-                    client->stream_pos == 0)) {
-                       construct_header(client);
-               }
-       }
 }
        
 void Server::set_mark_pool(int stream_index, MarkPool *mark_pool)
 }
        
 void Server::set_mark_pool(int stream_index, MarkPool *mark_pool)
@@ -528,8 +515,13 @@ int Server::parse_request(Client *client)
                return 404;  // Not found.
        }
 
                return 404;  // Not found.
        }
 
+       Stream *stream = streams[url_map_it->second];
+       if (stream->http_header.empty()) {
+               return 503;  // Service unavailable.
+       }
+
        client->url = request_tokens[1];
        client->url = request_tokens[1];
-       client->stream = streams[url_map_it->second];
+       client->stream = stream;
        if (client->stream->mark_pool != NULL) {
                client->fwmark = client->stream->mark_pool->get_mark();
        } else {
        if (client->stream->mark_pool != NULL) {
                client->fwmark = client->stream->mark_pool->get_mark();
        } else {