]> git.sesse.net Git - cubemap/commitdiff
When we get a header, retroactively send it out to all clients that have received...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 22:51:12 +0000 (00:51 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 22:51:12 +0000 (00:51 +0200)
server.cpp
server.h

index c80f2da2e2c354729702ef04ba9f7068ed5ec14c..f47de543e2b69a1350138ab0cb3c0f979fe07484 100644 (file)
@@ -200,6 +200,18 @@ void Server::set_header(const string &stream_id, const string &header)
 {
        MutexLock lock(&mutex);
        find_stream(stream_id)->header = 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::SENDING_DATA &&
+                   client->bytes_sent == 0) {
+                       construct_header(client);
+               }
+       }
 }
        
 void Server::add_data(const string &stream_id, const char *data, size_t bytes)
@@ -273,6 +285,7 @@ void Server::process_client(Client *client)
                }
 
                parse_request(client);
+               construct_header(client);
                break;
        }
        case Client::SENDING_HEADER: {
@@ -356,9 +369,11 @@ void Server::parse_request(Client *client)
        // TODO: Actually parse the request. :-)
        client->stream_id = "stream";
        client->request.clear();
+}
 
-       // Construct the header.
-       client->header = "HTTP/1.0 200 OK\r\n  Content-type: video/x-flv\r\nCache-Control: no-cache\r\nContent-type: todo/fixme\r\n\r\n" +
+void Server::construct_header(Client *client)
+{
+       client->header = "HTTP/1.0 200 OK\r\nContent-type: video/x-flv\r\nCache-Control: no-cache\r\n\r\n" +
                find_stream(client->stream_id)->header;
 
        // Switch states.
index 99009600a46f0401a325ced52e04f542c57b602f..65ac6b805435f413d4e6bd0f5bfbf84e747aacff 100644 (file)
--- a/server.h
+++ b/server.h
@@ -126,10 +126,13 @@ private:
        // Close a given client socket, and clean up after it.
        void close_client(Client *client);
 
-       // Parse the HTTP request, construct the header, and set the client into
-       // the SENDING_HEADER state.
+       // Parse the HTTP request.
        void parse_request(Client *client);
 
+       // Construct the HTTP header, and set the client into
+       // the SENDING_HEADER state.
+       void construct_header(Client *client);
+
        // Put client to sleep, since there is no more data for it; we will on
        // longer listen on POLLOUT until we get more data. Also, it will be put
        // in the list of clients to wake up when we do.