]> git.sesse.net Git - cubemap/blobdiff - httpinput.cpp
Add an assert, to hopefully catch a bug.
[cubemap] / httpinput.cpp
index cc618bc7849b11464b29afac557af6228c5c497c..6de67b251cc4b132c75146b7a2927dda541205f3 100644 (file)
@@ -86,7 +86,7 @@ int HTTPInput::lookup_and_connect(const string &host, const string &port)
 {
        addrinfo *ai;
        int err = getaddrinfo(host.c_str(), port.c_str(), NULL, &ai);
-       if (err == -1) {
+       if (err != 0) {
                log(WARNING, "[%s] Lookup of '%s' failed (%s).",
                        url.c_str(), host.c_str(), gai_strerror(err));
                return -1;
@@ -95,7 +95,7 @@ int HTTPInput::lookup_and_connect(const string &host, const string &port)
        addrinfo *base_ai = ai;
 
        // Connect to everything in turn until we have a socket.
-       while (ai && !should_stop()) {
+       for ( ; ai && !should_stop(); ai = ai->ai_next) {
                int sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
                if (sock == -1) {
                        // Could be e.g. EPROTONOSUPPORT. The show must go on.
@@ -153,7 +153,6 @@ int HTTPInput::lookup_and_connect(const string &host, const string &port)
                }
 
                safe_close(sock);
-               ai = ai->ai_next;
        }
 
        // Give the last one as error.
@@ -265,6 +264,7 @@ void HTTPInput::do_work()
                        request_bytes_sent = 0;
                        response.clear();
                        pending_data.clear();
+                       has_metacube_header = false;
                        for (size_t i = 0; i < stream_indices.size(); ++i) {
                                servers->set_header(stream_indices[i], "", "");
                        }
@@ -491,6 +491,7 @@ void HTTPInput::drop_pending_data(size_t num_bytes)
        }
        log(WARNING, "[%s] Dropping %lld junk bytes from stream, maybe it is not a Metacube stream?",
                url.c_str(), (long long)num_bytes);
+       assert(pending_data.size() >= num_bytes);
        pending_data.erase(pending_data.begin(), pending_data.begin() + num_bytes);
 }