2 #define _SERVERPOOL_H 1
12 #include "udpstream.h"
20 // Provides services such as load-balancing between a number of Server instances.
23 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, Acceptor *acceptor);
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, size_t prebuffering_bytes, Stream::Encoding encoding, Stream::Encoding src_encoding);
34 int add_stream_from_serialized(const StreamProto &stream, const std::vector<int> &data_fds);
35 void delete_stream(const std::string &url);
36 int add_udpstream(const sockaddr_in6 &dst, int pacing_rate, int ttl, int multicast_iface_index);
38 // Returns the stream index for the given URL (e.g. /foo.ts). Returns -1 on failure.
39 int lookup_stream_by_url(const std::string &url) const;
41 // Adds the given data to all the servers.
42 void set_header(int stream_index,
43 const std::string &http_header,
44 const std::string &stream_header);
45 void add_data(int stream_index, const char *data, size_t bytes, uint16_t metacube_flags);
47 // Sets the max pacing rate for all the servers.
48 void set_pacing_rate(int stream_index, uint32_t pacing_rate);
50 // Changes the given stream's backlog size on all the servers.
51 void set_backlog_size(int stream_index, size_t new_size);
53 // Changes the given stream's amount of forced prebuffering on all the servers.
54 void set_prebuffering_bytes(int stream_index, size_t new_amount);
56 // Changes the given stream's output encoding type on all the servers.
57 void set_encoding(int stream_index, Stream::Encoding encoding);
59 // Changes the given stream's input encoding type on all the servers.
60 void set_src_encoding(int stream_index, Stream::Encoding encoding);
62 // Adds the given gen204 endpoint to all the servers.
63 void add_gen204(const std::string &url, const std::string &allow_origin);
65 // Prepares all the servers for accepting TLS connections from the given acceptor.
66 // (They need a private context, since the contexts are not definde to be thread-safe.)
67 void create_tls_context_for_acceptor(const Acceptor *acceptor);
69 // Starts all the servers.
72 // Stops all the servers.
75 std::vector<ClientStats> get_client_stats() const;
78 std::unique_ptr<Server[]> servers;
79 int num_servers, clients_added = 0;
81 // Our indexing is currently rather primitive; every stream_index in
82 // [0, num_http_streams) maps to a HTTP stream (of which every Server
83 // has exactly one copy), and after that, it's mapping directly into
85 int num_http_streams = 0;
86 std::vector<std::unique_ptr<UDPStream>> udp_streams;
88 ServerPool(const ServerPool &);
91 #endif // !defined(_SERVERPOOL_H)