]> git.sesse.net Git - cubemap/blob - serverpool.h
Fix compilation error with newer glibc; broken after IWYU.
[cubemap] / serverpool.h
1 #ifndef _SERVERPOOL_H
2 #define _SERVERPOOL_H 1
3
4 #include <stddef.h>
5 #include <string>
6 #include <vector>
7
8 #include "server.h"
9 #include "state.pb.h"
10 #include "stream.h"
11 #include "udpstream.h"
12
13 class MarkPool;
14 class Server;
15 class UDPStream;
16 struct ClientStats;
17 struct sockaddr_in6;
18
19 // Provides services such as load-balancing between a number of Server instances.
20 class ServerPool {
21 public:
22         ServerPool(int num_servers);
23         ~ServerPool();
24
25         // Fills streams() and clients().
26         CubemapStateProto serialize();
27
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);
31
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         void delete_stream(const std::string &url);
36         int add_udpstream(const sockaddr_in6 &dst, MarkPool *mark_pool, int pacing_rate);
37
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;
40
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, StreamStartSuitability suitable_for_stream_start);
46
47         // Connects the given stream to the given mark pool for all the servers.
48         void set_mark_pool(int stream_index, MarkPool *mark_pool);
49
50         // Sets the max pacing rate for all the servers.
51         void set_pacing_rate(int stream_index, uint32_t pacing_rate);
52
53         // Changes the given stream's backlog size on all the servers.
54         void set_backlog_size(int stream_index, size_t new_size);
55
56         // Changes the given stream's encoding type on all the servers.
57         void set_encoding(int stream_index, Stream::Encoding encoding);
58
59         // Starts all the servers.
60         void run();
61
62         // Stops all the servers.
63         void stop();
64
65         std::vector<ClientStats> get_client_stats() const;
66
67 private:
68         Server *servers;
69         int num_servers, clients_added;
70
71         // Our indexing is currently rather primitive; every stream_index in
72         // [0, num_http_streams) maps to a HTTP stream (of which every Server
73         // has exactly one copy), and after that, it's mapping directly into
74         // <udp_streams>.
75         int num_http_streams;
76         std::vector<UDPStream *> udp_streams;
77
78         ServerPool(const ServerPool &);
79 };
80
81 #endif  // !defined(_SERVERPOOL_H)