2 #define _SERVERPOOL_H 1
11 #include "udpstream.h"
19 // Provides services such as load-balancing between a number of Server instances.
22 ServerPool(int num_servers);
25 // Fills streams() and clients().
26 CubemapStateProto serialize();
28 // Picks a server (round-robin) and allocates the given client to it.
29 void add_client(int sock);
30 void add_client_from_serialized(const ClientProto &client);
32 // Adds the given stream to all the servers. Returns the stream index.
33 int add_stream(const std::string &url, size_t backlog_size, Stream::Encoding encoding);
34 int add_stream_from_serialized(const StreamProto &stream, const std::vector<int> &data_fds);
35 int add_udpstream(const sockaddr_in6 &dst, MarkPool *mark_pool);
37 // Returns the stream index for the given URL (e.g. /foo.ts). Returns -1 on failure.
38 int lookup_stream_by_url(const std::string &url) const;
40 // Adds the given data to all the servers.
41 void set_header(int stream_index,
42 const std::string &http_header,
43 const std::string &stream_header);
44 void add_data(int stream_index, const char *data, size_t bytes, StreamStartSuitability suitable_for_stream_start);
46 // Connects the given stream to the given mark pool for all the servers.
47 void set_mark_pool(int stream_index, MarkPool *mark_pool);
49 // Changes the given stream's backlog size on all the servers.
50 void set_backlog_size(int stream_index, size_t new_size);
52 // Changes the given stream's encoding type on all the servers.
53 void set_encoding(int stream_index, Stream::Encoding encoding);
55 // Starts all the servers.
58 // Stops all the servers.
61 std::vector<ClientStats> get_client_stats() const;
65 int num_servers, clients_added;
67 // Our indexing is currently rather primitive; every stream_index in
68 // [0, num_http_streams) maps to a HTTP stream (of which every Server
69 // has exactly one copy), and after that, it's mapping directly into
72 std::vector<UDPStream *> udp_streams;
74 ServerPool(const ServerPool &);
77 #endif // !defined(_SERVERPOOL_H)