X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=httpinput.cpp;h=1e607d4efc50ebbb9ed3936f4990e6b07d14c30c;hp=1db4f91f16e0221f6afcf886111142d7a36a097e;hb=f2a5ca1fe4798ebd87d16550198118e2172243f4;hpb=239a9eab1a2468b401183745a24b2fbd590a6998 diff --git a/httpinput.cpp b/httpinput.cpp index 1db4f91..1e607d4 100644 --- a/httpinput.cpp +++ b/httpinput.cpp @@ -1,29 +1,26 @@ +#include +#include +#include +#include +#include +#include #include +#include #include -#include -#include -#include -#include -#include -#include #include -#include #include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include -#include "metacube.h" -#include "mutexlock.h" #include "httpinput.h" -#include "server.h" -#include "serverpool.h" +#include "metacube.h" #include "parse.h" +#include "serverpool.h" #include "state.pb.h" +#include "version.h" using namespace std; @@ -56,6 +53,18 @@ HTTPInput::HTTPInput(const InputProto &serialized) parse_url(url, &protocol, &host, &port, &path); // Don't care if it fails. } +void HTTPInput::close_socket() +{ + int ret; + do { + ret = close(sock); + } while (ret == -1 && errno == EINTR); + + if (ret == -1) { + perror("close()"); + } +} + InputProto HTTPInput::serialize() const { InputProto serialized; @@ -100,6 +109,15 @@ int HTTPInput::lookup_and_connect(const string &host, const string &port) return sock; } + do { + err = close(sock); + } while (err == -1 && errno == EINTR); + + if (err == -1) { + perror("close"); + // Can still continue. + } + ai = ai->ai_next; } @@ -163,7 +181,7 @@ bool HTTPInput::parse_response(const std::string &request) // TODO: Make case-insensitive. // XXX: Use a Via: instead? if (parameters.count("Server") == 0) { - parameters.insert(make_pair("Server", "metacube/0.1")); + parameters.insert(make_pair("Server", SERVER_IDENTIFICATION)); } else { for (multimap::iterator it = parameters.begin(); it != parameters.end(); @@ -171,7 +189,7 @@ bool HTTPInput::parse_response(const std::string &request) if (it->first != "Server") { continue; } - it->second = "metacube/0.1 (reflecting: " + it->second + ")"; + it->second = SERVER_IDENTIFICATION " (reflecting: " + it->second + ")"; } } @@ -214,6 +232,8 @@ void HTTPInput::do_work() request.clear(); request_bytes_sent = 0; response.clear(); + pending_data.clear(); + servers->set_header(stream_id, ""); { string protocol; // Thrown away.