]> git.sesse.net Git - cubemap/blobdiff - stream.cpp
When unwrapping in set_backlog_size, do not add a spurious Metacube header.
[cubemap] / stream.cpp
index 109d2fd4a90116398e8b638816872cabf06b22ce..5ea2cd03601491f8fe64070fd4b33b71f33dd4d8 100644 (file)
@@ -1,14 +1,15 @@
-#include <arpa/inet.h>
+#include <assert.h>
 #include <errno.h>
-#include <stdio.h>
+#include <netinet/in.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <string>
 #include <vector>
 
-#include "state.pb.h"
 #include "log.h"
 #include "metacube.h"
+#include "state.pb.h"
 #include "stream.h"
 #include "util.h"
 
@@ -30,13 +31,7 @@ Stream::Stream(const string &stream_id, size_t backlog_size, Encoding encoding)
 Stream::~Stream()
 {
        if (data_fd != -1) {
-               int ret;
-               do {
-                       ret = close(data_fd);
-               } while (ret == -1 && errno == EINTR);
-               if (ret == -1) {
-                       log_perror("close");
-               }
+               safe_close(data_fd);
        }
 }
 
@@ -109,11 +104,14 @@ void Stream::set_backlog_size(size_t new_size)
 
        // Create a new, empty data file.
        data_fd = make_tempfile("");
+       if (data_fd == -1) {
+               exit(1);
+       }
        backlog_size = new_size;
 
        // Now cheat a bit by rewinding, and adding all the old data back.
        bytes_received -= existing_data.size();
-       add_data(existing_data.data(), existing_data.size());
+       add_data_raw(existing_data.data(), existing_data.size());
 }
 
 void Stream::put_client_to_sleep(Client *client)