Rename ping to gen204, and change the response type to a 204 No Response, since that...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Aug 2015 11:26:20 +0000 (13:26 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Aug 2015 11:26:20 +0000 (13:26 +0200)
config.cpp
config.h
cubemap.config.sample
main.cpp
server.cpp
server.h
serverpool.cpp
serverpool.h

index 9ff0a03..0b5ed20 100644 (file)
@@ -322,23 +322,23 @@ bool parse_udpstream(const ConfigLine &line, Config *config)
        return true;
 }
 
-bool parse_ping(const ConfigLine &line, Config *config)
+bool parse_gen204(const ConfigLine &line, Config *config)
 {
        if (line.arguments.size() != 1) {
-               log(ERROR, "'ping' takes exactly one argument");
+               log(ERROR, "'gen204' takes exactly one argument");
                return false;
        }
 
-       PingConfig ping;
-       ping.url = line.arguments[0];
+       Gen204Config gen204;
+       gen204.url = line.arguments[0];
 
        // Parse the CORS origin, if it exists.
        map<string, string>::const_iterator allow_origin_it = line.parameters.find("allow_origin");
        if (allow_origin_it != line.parameters.end()) {
-               ping.allow_origin = allow_origin_it->second;
+               gen204.allow_origin = allow_origin_it->second;
        }
 
-       config->pings.push_back(ping);
+       config->pings.push_back(gen204);
        return true;
 }
 
@@ -443,8 +443,8 @@ bool parse_config(const string &filename, Config *config)
                        if (!parse_udpstream(line, config)) {
                                return false;
                        }
-               } else if (line.keyword == "ping") {
-                       if (!parse_ping(line, config)) {
+               } else if (line.keyword == "gen204") {
+                       if (!parse_gen204(line, config)) {
                                return false;
                        }
                } else if (line.keyword == "error_log") {
index 5a006ca..9a5cc57 100644 (file)
--- a/config.h
+++ b/config.h
@@ -26,7 +26,7 @@ struct UDPStreamConfig {
        int multicast_iface_index;  // Default is -1 (use operating system default).
 };
 
-struct PingConfig {
+struct Gen204Config {
        std::string url;  // As seen by the client.
        std::string allow_origin;  // Can be empty.
 };
@@ -45,7 +45,7 @@ struct Config {
        int num_servers;
        std::vector<StreamConfig> streams;
        std::vector<UDPStreamConfig> udpstreams;
-       std::vector<PingConfig> pings;
+       std::vector<Gen204Config> pings;
        std::vector<AcceptorConfig> acceptors;
        std::vector<LogConfig> log_destinations;
 
index b03ea65..35bfe5e 100644 (file)
@@ -93,11 +93,11 @@ udpstream 193.35.52.50:5001 src=http://pannekake.samfundet.no:9094/frikanalen.ts
 udpstream 233.252.0.1:5002 src=http://pannekake.samfundet.no:9094/frikanalen.ts.metacube ttl=32 multicast_output_interface=eth1
 
 # A type of HTTP resource that is not a stream, but rather just a very simple
-# document that contains “pong” and nothing else. allow_origin= is optional;
+# document that a HTTP 204 response and nothing else. allow_origin= is optional;
 # if it is set, the response will contain an Access-Control-Allow-Origin header
 # with the given value, allowing the ping response to be read (and
 # differentiated from an error) from a remote domain using XHR.
 #
-# If you have a stream and a ping endpoint with the same URL, the stream takes
+# If you have a stream and a gen204 endpoint with the same URL, the stream takes
 # precedence and the ping endpoint is silently ignored.
-ping /ping allow_origin=*
+gen204 /ping allow_origin=*
index faf4be8..1b6fb4f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -232,10 +232,10 @@ void create_streams(const Config &config,
                }
        }
 
-       // HTTP ping endpoints.
+       // HTTP gen204 endpoints.
        for (unsigned i = 0; i < config.pings.size(); ++i) {
-               const PingConfig &ping_config = config.pings[i];
-               servers->add_ping(ping_config.url, ping_config.allow_origin);
+               const Gen204Config &ping_config = config.pings[i];
+               servers->add_gen204(ping_config.url, ping_config.allow_origin);
        }
 }
        
index 9d15e08..9b83ddc 100644 (file)
@@ -359,7 +359,7 @@ void Server::set_pacing_rate(int stream_index, uint32_t pacing_rate)
        streams[stream_index]->pacing_rate = pacing_rate;
 }
 
-void Server::add_ping(const std::string &url, const std::string &allow_origin)
+void Server::add_gen204(const std::string &url, const std::string &allow_origin)
 {
        MutexLock lock(&mutex);
        assert(clients.empty());
@@ -425,8 +425,8 @@ read_request_again:
                int error_code = parse_request(client);
                if (error_code == 200) {
                        construct_header(client);
-               } else if (error_code == -200) {
-                       construct_pong(client);
+               } else if (error_code == 204) {
+                       construct_204(client);
                } else {
                        construct_error(client, error_code);
                }
@@ -659,7 +659,7 @@ int Server::parse_request(Client *client)
                if (ping_url_map_it == ping_url_map.end()) {
                        return 404;  // Not found.
                } else {
-                       return -200;  // Special internal error code for pong.
+                       return 204;  // No error.
                }
        }
 
@@ -737,27 +737,23 @@ void Server::construct_error(Client *client, int error_code)
        }
 }
 
-void Server::construct_pong(Client *client)
+void Server::construct_204(Client *client)
 {
        map<string, string>::const_iterator ping_url_map_it = ping_url_map.find(client->url);
        assert(ping_url_map_it != ping_url_map.end());
 
        if (ping_url_map_it->second.empty()) {
                client->header_or_short_response =
-                       "HTTP/1.0 200 OK\r\n"
-                       "Content-type: text/plain\r\n"
-                       "\r\n"
-                       "Pong!\r\n";
+                       "HTTP/1.0 204 No Content\r\n"
+                       "\r\n";
        } else {
-               char pong[256];
-               snprintf(pong, 256,
-                        "HTTP/1.0 200 OK\r\n"
-                        "Content-type: text/plain\r\n"
+               char response[256];
+               snprintf(response, 256,
+                        "HTTP/1.0 204 No Content\r\n"
                         "Access-Control-Allow-Origin: %s\r\n"
-                        "\r\n"
-                        "Pong!\r\n",
+                        "\r\n",
                         ping_url_map_it->second.c_str());
-               client->header_or_short_response = pong;
+               client->header_or_short_response = response;
        }
 
        // Switch states.
index 7297fd7..073ef73 100644 (file)
--- a/server.h
+++ b/server.h
@@ -61,7 +61,7 @@ public:
        void set_backlog_size(int stream_index, size_t new_size);
        void set_prebuffering_bytes(int stream_index, size_t new_amount);
        void set_encoding(int stream_index, Stream::Encoding encoding);
-       void add_ping(const std::string &url, const std::string &allow_origin);
+       void add_gen204(const std::string &url, const std::string &allow_origin);
 
 private:
        // Mutex protecting queued_add_clients.
@@ -134,8 +134,7 @@ private:
        // Close a given client socket, and clean up after it.
        void close_client(Client *client);
 
-       // Parse the HTTP request. Returns a HTTP status code (200/400/404),
-       // or -200 for a pong (which should be answered with 200).
+       // Parse the HTTP request. Returns a HTTP status code (200/204/400/404).
        int parse_request(Client *client);
 
        // Construct the HTTP header, and set the client into
@@ -146,8 +145,8 @@ private:
        // the SENDING_SHORT_RESPONSE state.
        void construct_error(Client *client, int error_code);
 
-       // Construct a pong, and set the client into the SENDING_SHORT_RESPONSE state.
-       void construct_pong(Client *client);
+       // Construct a 204, and set the client into the SENDING_SHORT_RESPONSE state.
+       void construct_204(Client *client);
 
        void process_queued_data();
        void skip_lost_data(Client *client);
index 3159f33..c77c30e 100644 (file)
@@ -163,10 +163,10 @@ void ServerPool::add_data(int stream_index, const char *data, size_t bytes, Stre
        }
 }
 
-void ServerPool::add_ping(const std::string &url, const std::string &allow_origin)
+void ServerPool::add_gen204(const std::string &url, const std::string &allow_origin)
 {
        for (int i = 0; i < num_servers; ++i) {
-               servers[i].add_ping(url, allow_origin);
+               servers[i].add_gen204(url, allow_origin);
        }
 }
 
index cc37e17..44084bc 100644 (file)
@@ -55,8 +55,8 @@ public:
        // Changes the given stream's encoding type on all the servers.
        void set_encoding(int stream_index, Stream::Encoding encoding);
 
-       // Adds the given ping endpoint to all the servers.
-       void add_ping(const std::string &url, const std::string &allow_origin);
+       // Adds the given gen204 endpoint to all the servers.
+       void add_gen204(const std::string &url, const std::string &allow_origin);
 
        // Starts all the servers.
        void run();