X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=be583e490d5223358d5aef68c8b826654b06e51d;hp=e9bc654eb1a3cbe4d667f3bafef6119aabec01fa;hb=58dd753c464d917dc446e2cbb4c01fd750d4eb87;hpb=20e85bd6901355cc40a6cfb4c0deb7232d9aa63f diff --git a/server.cpp b/server.cpp index e9bc654..be583e4 100644 --- a/server.cpp +++ b/server.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -300,7 +301,7 @@ void Server::add_client_from_serialized(const ClientProto &client, const vector< int Server::lookup_stream_by_url(const string &url) const { - map::const_iterator stream_url_it = stream_url_map.find(url); + const auto stream_url_it = stream_url_map.find(url); if (stream_url_it == stream_url_map.end()) { return -1; } @@ -909,12 +910,12 @@ int Server::parse_request(Client *client) // Parse the headers, for logging purposes. // TODO: Case-insensitivity. - multimap headers = extract_headers(lines, client->remote_addr); - multimap::const_iterator referer_it = headers.find("Referer"); + unordered_multimap headers = extract_headers(lines, client->remote_addr); + const auto referer_it = headers.find("Referer"); if (referer_it != headers.end()) { client->referer = referer_it->second; } - multimap::const_iterator user_agent_it = headers.find("User-Agent"); + const auto user_agent_it = headers.find("User-Agent"); if (user_agent_it != headers.end()) { client->user_agent = user_agent_it->second; } @@ -984,25 +985,25 @@ int Server::parse_request(Client *client) client->close_after_response = true; client->http_11 = false; } else { - multimap::const_iterator connection_it = headers.find("Connection"); + const auto connection_it = headers.find("Connection"); if (connection_it != headers.end() && connection_it->second == "close") { client->close_after_response = true; } } - map::const_iterator stream_url_map_it = stream_url_map.find(url); + const auto stream_url_map_it = stream_url_map.find(url); if (stream_url_map_it != stream_url_map.end()) { // Serve a regular stream.. client->stream = streams[stream_url_map_it->second].get(); client->serving_hls_playlist = false; } else { - map::const_iterator stream_hls_url_map_it = stream_hls_url_map.find(url); + const auto stream_hls_url_map_it = stream_hls_url_map.find(url); if (stream_hls_url_map_it != stream_hls_url_map.end()) { // Serve HLS playlist. client->stream = streams[stream_hls_url_map_it->second].get(); client->serving_hls_playlist = true; } else { - map::const_iterator ping_url_map_it = ping_url_map.find(url); + const auto ping_url_map_it = ping_url_map.find(url); if (ping_url_map_it == ping_url_map.end()) { return 404; // Not found. } else { @@ -1165,7 +1166,7 @@ void Server::construct_hls_playlist(Client *client) void Server::construct_204(Client *client) { - map::const_iterator ping_url_map_it = ping_url_map.find(client->url); + const auto ping_url_map_it = ping_url_map.find(client->url); assert(ping_url_map_it != ping_url_map.end()); string response; @@ -1247,6 +1248,14 @@ bool Server::more_requests(Client *client) // Log to access_log. access_log->write(client->get_stats()); + // Flush pending data; does not cancel out TCP_CORK (since that still takes priority), + // but does a one-off flush. + int one = 1; + if (setsockopt(client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)) == -1) { + log_perror("setsockopt(TCP_NODELAY)"); + // Can still continue. + } + // Switch states and reset the parsers. We don't reset statistics. client->state = Client::READING_REQUEST; client->url.clear();