]> git.sesse.net Git - cubemap/blob - serverpool.h
Ignore SIGPIPE, so we do not die when a client shuts down at the wrong time.
[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
11 class MarkPool;
12 class Server;
13 struct ClientStats;
14
15 // Provides services such as load-balancing between a number of Server instances.
16 class ServerPool {
17 public:
18         ServerPool(int num_servers);
19         ~ServerPool();
20
21         // Fills streams() and clients().
22         CubemapStateProto serialize();
23
24         // Picks a server (round-robin) and allocates the given client to it.
25         void add_client(int sock);
26         void add_client_from_serialized(const ClientProto &client);
27
28         // Adds the given stream to all the servers.
29         void add_stream(const std::string &stream_id, size_t backlog_size);
30         void add_stream_from_serialized(const StreamProto &stream);
31
32         // Adds the given data to all the servers.
33         void set_header(const std::string &stream_id, const std::string &header);
34         void add_data(const std::string &stream_id, const char *data, size_t bytes);
35
36         // Connects the given stream to the given mark pool for all the servers.
37         void set_mark_pool(const std::string &stream_id, MarkPool *mark_pool);
38
39         // Changes the given stream's backlog size on all the servers.
40         void set_backlog_size(const std::string &stream_id, size_t new_size);
41
42         // Starts all the servers.
43         void run();
44
45         // Stops all the servers.
46         void stop();
47
48         std::vector<ClientStats> get_client_stats() const;
49
50 private:
51         Server *servers;
52         int num_servers, clients_added;
53
54         ServerPool(const ServerPool &);
55 };
56
57 #endif  // !defined(_SERVERPOOL_H)