X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=serverpool.cpp;h=60a913d56146ecf58f7f9b72b82af0bb7adeb1f5;hp=cf6933ccda181e23f4f7f7d85e353ec11b7d805a;hb=3b8ad87137cff7522ed12f4675d5ff26933bc94a;hpb=d9b0536b128e10447a986f7b6ea2b5c93252c80f diff --git a/serverpool.cpp b/serverpool.cpp index cf6933c..60a913d 100644 --- a/serverpool.cpp +++ b/serverpool.cpp @@ -1,4 +1,9 @@ +#include + +#include "client.h" +#include "server.h" #include "serverpool.h" +#include "state.pb.h" using namespace std; @@ -13,6 +18,25 @@ ServerPool::~ServerPool() { delete[] servers; } + +CubemapStateProto ServerPool::serialize() +{ + CubemapStateProto state; + + for (int i = 0; i < num_servers; ++i) { + CubemapStateProto local_state = servers[i].serialize(); + + // The stream state should be identical between the servers, so we only store it once. + if (i == 0) { + state.mutable_streams()->MergeFrom(local_state.streams()); + } + for (int j = 0; j < local_state.clients_size(); ++j) { + state.add_clients()->MergeFrom(local_state.clients(j)); + } + } + + return state; +} void ServerPool::add_client(int sock) { @@ -24,10 +48,10 @@ void ServerPool::add_client_from_serialized(const ClientProto &client) servers[clients_added++ % num_servers].add_client_from_serialized(client); } -void ServerPool::add_stream(const std::string &stream_id) +void ServerPool::add_stream(const string &stream_id, size_t backlog_size, Stream::Encoding encoding) { for (int i = 0; i < num_servers; ++i) { - servers[i].add_stream(stream_id); + servers[i].add_stream(stream_id, backlog_size, encoding); } } @@ -38,14 +62,14 @@ void ServerPool::add_stream_from_serialized(const StreamProto &stream) } } -void ServerPool::set_header(const std::string &stream_id, const std::string &header) +void ServerPool::set_header(const string &stream_id, const string &http_header, const string &stream_header) { for (int i = 0; i < num_servers; ++i) { - servers[i].set_header(stream_id, header); + servers[i].set_header(stream_id, http_header, stream_header); } } -void ServerPool::add_data(const std::string &stream_id, const char *data, size_t bytes) +void ServerPool::add_data(const string &stream_id, const char *data, size_t bytes) { for (int i = 0; i < num_servers; ++i) { servers[i].add_data_deferred(stream_id, data, bytes); @@ -76,9 +100,23 @@ vector ServerPool::get_client_stats() const return ret; } -void ServerPool::set_mark_pool(const std::string &stream_id, MarkPool *mark_pool) +void ServerPool::set_mark_pool(const string &stream_id, MarkPool *mark_pool) { for (int i = 0; i < num_servers; ++i) { servers[i].set_mark_pool(stream_id, mark_pool); } } + +void ServerPool::set_backlog_size(const string &stream_id, size_t new_size) +{ + for (int i = 0; i < num_servers; ++i) { + servers[i].set_backlog_size(stream_id, new_size); + } +} + +void ServerPool::set_encoding(const string &stream_id, Stream::Encoding encoding) +{ + for (int i = 0; i < num_servers; ++i) { + servers[i].set_encoding(stream_id, encoding); + } +}