]> git.sesse.net Git - cubemap/blobdiff - httpinput.cpp
When HTTPInput disconnects, also clear the header.
[cubemap] / httpinput.cpp
index 1db4f91f16e0221f6afcf886111142d7a36a097e..1e607d4efc50ebbb9ed3936f4990e6b07d14c30c 100644 (file)
@@ -1,29 +1,26 @@
+#include <assert.h>
+#include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <poll.h>
+#include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <stdint.h>
-#include <assert.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <pthread.h>
-#include <sys/types.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #include <sys/socket.h>
-#include <netdb.h>
-#include <poll.h>
-#include <signal.h>
-#include <errno.h>
-#include <vector>
-#include <string>
+#include <unistd.h>
 #include <map>
+#include <string>
+#include <utility>
+#include <vector>
 
-#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<string, string>::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.