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