]> git.sesse.net Git - cubemap/blobdiff - stream.h
Move iovecs around instead of having single data buffers. Hopefully a tad more effici...
[cubemap] / stream.h
index 97451f0c8afe7fe08dc57b7c44c18e64de4a0615..33fb55eeeab9180589d57275b182f806dcb3b9a3 100644 (file)
--- a/stream.h
+++ b/stream.h
@@ -7,6 +7,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 #include <string>
 #include <vector>
 
@@ -70,7 +71,8 @@ struct Stream {
        MarkPool *mark_pool;
 
        // Queued data, if any. Protected by the owning Server's <queued_data_mutex>.
-       std::string queued_data;
+       // The data pointers in the iovec are owned by us.
+       std::vector<iovec> queued_data;
 
        // Put client to sleep, since there is no more data for it; we will on
        // longer listen on POLLOUT until we get more data. Also, it will be put
@@ -78,6 +80,7 @@ struct Stream {
        void put_client_to_sleep(Client *client);
 
        // Add more data to <queued_data>, adding Metacube headers if needed.
+       // Does not take ownership of <data>.
        // You should hold the owning Server's <queued_data_mutex>.
        void add_data_deferred(const char *data, size_t bytes);
 
@@ -89,9 +92,9 @@ private:
        Stream(const Stream& other);
 
        // Adds data directly to the stream file descriptor, without adding headers or
-       // going through <queued_data>. You should hold the owning Server's
-       // <mutex>.
-       void add_data_raw(const char *data, ssize_t bytes);
+       // going through <queued_data>.
+       // You should hold the owning Server's <mutex>.
+       void add_data_raw(const std::vector<iovec> &data);
 };
 
 #endif  // !defined(_STREAM_H)