X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.h;h=e9b74315f1b3d5fdd6227d67c2c4160ccf89be58;hp=8d5261f6ca9b42fb84bab11776486cd44a67f125;hb=c5cdeee3a4c99abbf7303b47634b0a748e50bcb4;hpb=109af5c530539fd614d7d61dc33a4811ff631932 diff --git a/server.h b/server.h index 8d5261f..e9b7431 100644 --- a/server.h +++ b/server.h @@ -81,15 +81,22 @@ struct Stream { // Serialization/deserialization. Stream(const StreamProto &serialized); - StreamProto serialize() const; + StreamProto serialize(); std::string stream_id; // The HTTP response header, plus the video stream header (if any). std::string header; - // The stream data itself, stored in a circular buffer. - char *data; + // The stream data itself, stored in a circular buffer.q + // + // We store our data in a file, so that we can send the data to the + // kernel only once (with write()). We then use sendfile() for each + // client, which effectively zero-copies it out of the kernel's buffer + // cache. This is significantly more efficient than doing write() from + // a userspace memory buffer, since the latter makes the kernel copy + // the same data from userspace many times. + int data_fd; // How many bytes contains. Can very well be larger than BACKLOG_SIZE, // since the buffer wraps. @@ -217,7 +224,7 @@ private: void process_queued_data(); void add_client(int sock); - void add_data(const std::string &stream_id, const char *data, size_t bytes); + void add_data(const std::string &stream_id, const char *data, ssize_t bytes); }; #endif // !defined(_SERVER_H)