]> git.sesse.net Git - cubemap/blobdiff - server.cpp
Parse the HTTP header (more) properly, and send the headers on to any connecting...
[cubemap] / server.cpp
index f06685ab02224ea654b85d82f09d35a5dc456a5c..e91ba395ed6e2efa3c106fabf98ffa9756e159ef 100644 (file)
@@ -196,11 +196,11 @@ void Server::do_work()
                for (map<string, Stream *>::iterator stream_it = streams.begin();
                     stream_it != streams.end();
                     ++stream_it) {
-                       Stream *stream = stream_it->second;
-                       for (size_t i = 0; i < stream->to_process.size(); ++i) {
-                               process_client(stream->to_process[i]);
+                       vector<Client *> to_process;
+                       swap(stream_it->second->to_process, to_process);
+                       for (size_t i = 0; i < to_process.size(); ++i) {
+                               process_client(to_process[i]);
                        }
-                       stream->to_process.clear();
                }
        }
 }
@@ -538,8 +538,7 @@ int Server::parse_request(Client *client)
 
 void Server::construct_header(Client *client)
 {
-       client->header_or_error = "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;
+       client->header_or_error = find_stream(client->stream_id)->header;
 
        // Switch states.
        client->state = Client::SENDING_HEADER;
@@ -575,6 +574,13 @@ void Server::construct_error(Client *client, int error_code)
                exit(1);
        }
 }
+
+template<class T>
+void delete_from(vector<T> *v, T elem)
+{
+       typename vector<T>::iterator new_end = remove(v->begin(), v->end(), elem);
+       v->erase(new_end, v->end());
+}
        
 void Server::close_client(Client *client)
 {
@@ -585,12 +591,8 @@ void Server::close_client(Client *client)
 
        // This client could be sleeping, so we'll need to fix that. (Argh, O(n).)
        if (client->stream != NULL) {
-               vector<Client *>::iterator new_end =
-                       remove(client->stream->sleeping_clients.begin(),
-                              client->stream->sleeping_clients.end(),
-                              client);
-               client->stream->sleeping_clients.erase(
-                       new_end, client->stream->sleeping_clients.end());
+               delete_from(&client->stream->sleeping_clients, client);
+               delete_from(&client->stream->to_process, client);
        }
        
        // Bye-bye!