// 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 <data> contains. Can very well be larger than BACKLOG_SIZE,
// since the buffer wraps.
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)