#include "accesslog.h"
#include "log.h"
#include "metacube2.h"
-#include "mutexlock.h"
#include "parse.h"
#include "server.h"
#include "state.pb.h"
Server::Server()
{
- pthread_mutex_init(&mutex, nullptr);
- pthread_mutex_init(&queued_clients_mutex, nullptr);
-
epoll_fd = epoll_create(1024); // Size argument is ignored.
if (epoll_fd == -1) {
log_perror("epoll_fd");
{
vector<ClientStats> ret;
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
for (const auto &fd_and_client : clients) {
ret.push_back(fd_and_client.second.get_stats());
}
exit(1);
}
- MutexLock lock(&mutex); // We release the mutex between iterations.
+ lock_guard<mutex> lock(mu); // We release the mutex between iterations.
process_queued_data();
void Server::add_client_deferred(int sock, Acceptor *acceptor)
{
- MutexLock lock(&queued_clients_mutex);
+ lock_guard<mutex> lock(queued_clients_mutex);
queued_add_clients.push_back(std::make_pair(sock, acceptor));
}
void Server::add_client_from_serialized(const ClientProto &client)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
Stream *stream;
int stream_index = lookup_stream_by_url(client.url());
if (stream_index == -1) {
int Server::add_stream(const string &url, size_t backlog_size, size_t prebuffering_bytes, Stream::Encoding encoding, Stream::Encoding src_encoding)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
stream_url_map.insert(make_pair(url, streams.size()));
streams.emplace_back(new Stream(url, backlog_size, prebuffering_bytes, encoding, src_encoding));
return streams.size() - 1;
int Server::add_stream_from_serialized(const StreamProto &stream, int data_fd)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
stream_url_map.insert(make_pair(stream.url(), streams.size()));
streams.emplace_back(new Stream(stream, data_fd));
return streams.size() - 1;
void Server::set_backlog_size(int stream_index, size_t new_size)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->set_backlog_size(new_size);
}
void Server::set_prebuffering_bytes(int stream_index, size_t new_amount)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->prebuffering_bytes = new_amount;
}
void Server::set_encoding(int stream_index, Stream::Encoding encoding)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->encoding = encoding;
}
void Server::set_src_encoding(int stream_index, Stream::Encoding encoding)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->src_encoding = encoding;
}
void Server::set_header(int stream_index, const string &http_header, const string &stream_header)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->http_header = http_header;
void Server::set_pacing_rate(int stream_index, uint32_t pacing_rate)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(clients.empty());
assert(stream_index >= 0 && stream_index < ssize_t(streams.size()));
streams[stream_index]->pacing_rate = pacing_rate;
void Server::add_gen204(const std::string &url, const std::string &allow_origin)
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
assert(clients.empty());
ping_url_map[url] = allow_origin;
}
void Server::process_queued_data()
{
{
- MutexLock lock(&queued_clients_mutex);
+ lock_guard<mutex> lock(queued_clients_mutex);
for (const pair<int, Acceptor *> &id_and_acceptor : queued_add_clients) {
add_client(id_and_acceptor.first, id_and_acceptor.second);