]> git.sesse.net Git - cubemap/blob - serverpool.h
Fix a (harmless) close() warning that would come if we deleted a HTTP input that...
[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
12 class MarkPool;
13 class Server;
14 struct ClientStats;
15
16 // Provides services such as load-balancing between a number of Server instances.
17 class ServerPool {
18 public:
19         ServerPool(int num_servers);
20         ~ServerPool();
21
22         // Fills streams() and clients().
23         CubemapStateProto serialize();
24
25         // Picks a server (round-robin) and allocates the given client to it.
26         void add_client(int sock);
27         void add_client_from_serialized(const ClientProto &client);
28
29         // Adds the given stream to all the servers. Returns the stream index.
30         int add_stream(const std::string &url, size_t backlog_size, Stream::Encoding encoding);
31         int add_stream_from_serialized(const StreamProto &stream, const std::vector<int> &data_fds);
32
33         // Returns the stream index for the given URL (e.g. /foo.ts). Returns -1 on failure.
34         int lookup_stream_by_url(const std::string &url) const;
35
36         // Adds the given data to all the servers.
37         void set_header(int stream_index,
38                         const std::string &http_header,
39                         const std::string &stream_header);
40         void add_data(int stream_index, const char *data, size_t bytes);
41
42         // Connects the given stream to the given mark pool for all the servers.
43         void set_mark_pool(int stream_index, MarkPool *mark_pool);
44
45         // Changes the given stream's backlog size on all the servers.
46         void set_backlog_size(int stream_index, size_t new_size);
47
48         // Changes the given stream's encoding type on all the servers.
49         void set_encoding(int stream_index, Stream::Encoding encoding);
50
51         // Starts all the servers.
52         void run();
53
54         // Stops all the servers.
55         void stop();
56
57         std::vector<ClientStats> get_client_stats() const;
58
59 private:
60         Server *servers;
61         int num_servers, clients_added;
62
63         ServerPool(const ServerPool &);
64 };
65
66 #endif  // !defined(_SERVERPOOL_H)