X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=httpinput.cpp;h=19167f0b6b7404df6592dc9e9e2805bd9424325d;hp=2a101bd31dd94fecd9fa7cd9021e31867131163e;hb=46115862ece2cbd590bc4ae6fe06767869fa7668;hpb=562cf44b96b5c0260d1a1ab18b2dd2408b6d1fc8 diff --git a/httpinput.cpp b/httpinput.cpp index 2a101bd..19167f0 100644 --- a/httpinput.cpp +++ b/httpinput.cpp @@ -62,7 +62,9 @@ HTTPInput::HTTPInput(const InputProto &serialized) void HTTPInput::close_socket() { - safe_close(sock); + if (sock != -1) { + safe_close(sock); + } } InputProto HTTPInput::serialize() const @@ -84,17 +86,16 @@ 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)); - freeaddrinfo(ai); return -1; } 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. @@ -152,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. @@ -385,7 +385,7 @@ void HTTPInput::do_work() if (ret == 0) { // This really shouldn't happen... - log(ERROR, "[%s] Socket unexpectedly closed while reading header", + log(ERROR, "[%s] Socket unexpectedly closed while reading data", url.c_str()); state = CLOSING_SOCKET; continue;