]> git.sesse.net Git - cubemap/blob - serverpool.h
30839869013269544bb75fd076c349257d3382e6
[cubemap] / serverpool.h
1 #ifndef _SERVERPOOL_H
2 #define _SERVERPOOL_H 1
3
4 #include "server.h"
5
6 #include <vector>
7
8 // Provides services such as load-balancing between a number of Server instances.
9 class ServerPool {
10 public:
11         ServerPool(int num_servers);
12         ~ServerPool();
13
14         // Accessor. Only to be used in rare situations, really.
15         // The ServerPool retains ownership.
16         Server *get_server(int num) { return &servers[num]; }
17
18         // Picks a server (round-robin) and allocates the given client to it.
19         void add_client(int sock);
20         void add_client_from_serialized(const ClientProto &client);
21
22         // Adds the given stream to all the servers.
23         void add_stream(const std::string &stream_id);
24         void add_stream_from_serialized(const StreamProto &stream);
25
26         // Adds the given data to all the servers.
27         void set_header(const std::string &stream_id, const std::string &header);
28         void add_data(const std::string &stream_id, const char *data, size_t bytes);
29
30         // Starts all the servers.
31         void run();
32
33         std::vector<ClientStats> get_client_stats() const;
34
35 private:
36         Server *servers;
37         int num_servers, clients_added;
38
39         ServerPool(const ServerPool &);
40 };
41
42 #endif  // !defined(_SERVERPOOL_H)