4 // Representation of a single, muxed (we only really care about bytes/blocks) stream.
5 // Fed by Input, sent out by Server (to Client).
17 Stream(const std::string &stream_id, size_t backlog_size);
20 // Serialization/deserialization.
21 Stream(const StreamProto &serialized);
22 StreamProto serialize();
24 std::string stream_id;
26 // The HTTP response header, plus the video stream header (if any).
29 // The stream data itself, stored in a circular buffer.
31 // We store our data in a file, so that we can send the data to the
32 // kernel only once (with write()). We then use sendfile() for each
33 // client, which effectively zero-copies it out of the kernel's buffer
34 // cache. This is significantly more efficient than doing write() from
35 // a userspace memory buffer, since the latter makes the kernel copy
36 // the same data from userspace many times.
39 // How many bytes <data_fd> can hold (the buffer size).
42 // How many bytes this stream have received. Can very well be larger
43 // than <backlog_size>, since the buffer wraps.
44 size_t bytes_received;
46 // Clients that are in SENDING_DATA, but that we don't listen on,
47 // because we currently don't have any data for them.
48 // See put_client_to_sleep() and wake_up_all_clients().
49 std::vector<Client *> sleeping_clients;
51 // Clients that we recently got data for (when they were in
52 // <sleeping_clients>).
53 std::vector<Client *> to_process;
55 // What pool to fetch marks from, or NULL.
58 // Put client to sleep, since there is no more data for it; we will on
59 // longer listen on POLLOUT until we get more data. Also, it will be put
60 // in the list of clients to wake up when we do.
61 void put_client_to_sleep(Client *client);
63 // We have more data, so mark all clients that are sleeping as ready to go.
64 void wake_up_all_clients();
67 Stream(const Stream& other);
70 #endif // !defined(_STREAM_H)