{
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)
}
parse_request(client);
+ construct_header(client);
break;
}
case Client::SENDING_HEADER: {
// 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.
// 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.