]> git.sesse.net Git - cubemap/blobdiff - httpinput.cpp
When HTTPInput disconnects, also clear the header.
[cubemap] / httpinput.cpp
index 46f1358927312ba210cfa2f518e29991595d14ed..1e607d4efc50ebbb9ed3936f4990e6b07d14c30c 100644 (file)
@@ -1,30 +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 "version.h"
+#include "serverpool.h"
 #include "state.pb.h"
+#include "version.h"
 
 using namespace std;
 
@@ -57,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;
@@ -101,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;
        }
 
@@ -216,6 +233,7 @@ void HTTPInput::do_work()
                        request_bytes_sent = 0;
                        response.clear();
                        pending_data.clear();
+                       servers->set_header(stream_id, "");
 
                        {
                                string protocol;  // Thrown away.