+void ServerPool::add_client(int sock, Acceptor *acceptor)
+{
+ servers[clients_added++ % num_servers].add_client_deferred(sock, acceptor);
+}
+
+void ServerPool::add_client_from_serialized(const ClientProto &client, const std::vector<std::shared_ptr<const std::string>> &short_responses)
+{
+ servers[clients_added++ % num_servers].add_client_from_serialized(client, short_responses);
+}
+
+// It's fine to abuse clients_added here, since it's only ever used for round-robin purposes.
+void ServerPool::add_hls_zombie_from_serialized(const HLSZombieProto &hls_zombie)
+{
+ servers[clients_added++ % num_servers].add_hls_zombie_from_serialized(hls_zombie);
+}
+
+int ServerPool::lookup_stream_by_url(const string &url) const
+{
+ assert(servers != nullptr);
+ return servers[0].lookup_stream_by_url(url);
+}
+
+int ServerPool::add_stream(const string &url,
+ const string &hls_url,
+ size_t backlog_size,
+ size_t prebuffering_bytes,
+ Stream::Encoding encoding,
+ Stream::Encoding src_encoding,
+ unsigned hls_frag_duration,
+ size_t hls_backlog_margin,
+ const string &allow_origin)
+{
+ // Adding more HTTP streams after UDP streams would cause the UDP stream
+ // indices to move around, which is obviously not good.
+ assert(udp_streams.empty());
+
+ for (int i = 0; i < num_servers; ++i) {
+ int stream_index = servers[i].add_stream(url, hls_url, backlog_size, prebuffering_bytes, encoding, src_encoding, hls_frag_duration, hls_backlog_margin, allow_origin);
+ assert(stream_index == num_http_streams);
+ }
+ return num_http_streams++;
+}
+
+int ServerPool::add_stream_from_serialized(const StreamProto &stream, const vector<int> &data_fds)
+{
+ // Adding more HTTP streams after UDP streams would cause the UDP stream
+ // indices to move around, which is obviously not good.
+ assert(udp_streams.empty());
+
+ assert(!data_fds.empty());
+ string contents;
+ for (int i = 0; i < num_servers; ++i) {
+ int data_fd;
+ if (i < int(data_fds.size())) {
+ // Reuse one of the existing file descriptors.
+ data_fd = data_fds[i];
+ } else {
+ // Clone the first one.
+ if (contents.empty()) {
+ if (!read_tempfile(data_fds[0], &contents)) {
+ exit(1);
+ }
+ }
+ data_fd = make_tempfile(contents);
+ }
+
+ int stream_index = servers[i].add_stream_from_serialized(stream, data_fd);
+ assert(stream_index == num_http_streams);
+ }
+
+ // Close and delete any leftovers, if the number of servers was reduced.
+ for (size_t i = num_servers; i < data_fds.size(); ++i) {
+ safe_close(data_fds[i]); // Implicitly deletes the file.
+ }
+
+ return num_http_streams++;
+}
+
+int ServerPool::add_udpstream(const sockaddr_in6 &dst, int pacing_rate, int ttl, int multicast_iface_index)