X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=server.cpp;h=6fa4991b209f389da7f940aa73ff9462f472b8cd;hp=b381e7947d6d53d670042758cde01c7126b26738;hb=0e96bbf9ee0fbebd5fe3fba4d186c0e0d73c9a32;hpb=ec09f7a76908e4ab04337f941acf8e40a03a39ab diff --git a/server.cpp b/server.cpp index b381e79..6fa4991 100644 --- a/server.cpp +++ b/server.cpp @@ -19,7 +19,6 @@ #include "accesslog.h" #include "log.h" -#include "markpool.h" #include "metacube2.h" #include "mutexlock.h" #include "parse.h" @@ -199,6 +198,7 @@ void Server::add_client_from_serialized(const ClientProto &client) } if (client_ptr->state == Client::WAITING_FOR_KEYFRAME || + client_ptr->state == Client::PREBUFFERING || (client_ptr->state == Client::SENDING_DATA && client_ptr->stream_pos == client_ptr->stream->bytes_received)) { client_ptr->stream->put_client_to_sleep(client_ptr); @@ -216,11 +216,11 @@ int Server::lookup_stream_by_url(const std::string &url) const return url_it->second; } -int Server::add_stream(const string &url, size_t backlog_size, Stream::Encoding encoding) +int Server::add_stream(const string &url, size_t backlog_size, size_t prebuffering_bytes, Stream::Encoding encoding) { MutexLock lock(&mutex); url_map.insert(make_pair(url, streams.size())); - streams.push_back(new Stream(url, backlog_size, encoding)); + streams.push_back(new Stream(url, backlog_size, prebuffering_bytes, encoding)); return streams.size() - 1; } @@ -254,14 +254,6 @@ void Server::set_header(int stream_index, const string &http_header, const strin streams[stream_index]->stream_header = stream_header; } -void Server::set_mark_pool(int stream_index, MarkPool *mark_pool) -{ - MutexLock lock(&mutex); - assert(clients.empty()); - assert(stream_index >= 0 && stream_index < ssize_t(streams.size())); - streams[stream_index]->mark_pool = mark_pool; -} - void Server::set_pacing_rate(int stream_index, uint32_t pacing_rate) { MutexLock lock(&mutex); @@ -408,6 +400,18 @@ sending_header_or_error_again: return; } client->stream_pos = stream->last_suitable_starting_point; + client->state = Client::PREBUFFERING; + // Fall through. + } + case Client::PREBUFFERING: { + Stream *stream = client->stream; + size_t bytes_to_send = stream->bytes_received - client->stream_pos; + assert(bytes_to_send <= stream->backlog_size); + if (bytes_to_send < stream->prebuffering_bytes) { + // We don't have enough bytes buffered to start this client yet. + stream->put_client_to_sleep(client); + return; + } client->state = Client::SENDING_DATA; // Fall through. } @@ -516,16 +520,6 @@ int Server::parse_request(Client *client) client->url = request_tokens[1]; client->stream = stream; - if (client->stream->mark_pool != NULL) { - client->fwmark = client->stream->mark_pool->get_mark(); - } else { - client->fwmark = 0; // No mark. - } - if (setsockopt(client->sock, SOL_SOCKET, SO_MARK, &client->fwmark, sizeof(client->fwmark)) == -1) { - if (client->fwmark != 0) { - log_perror("setsockopt(SO_MARK)"); - } - } if (setsockopt(client->sock, SOL_SOCKET, SO_MAX_PACING_RATE, &client->stream->pacing_rate, sizeof(client->stream->pacing_rate)) == -1) { if (client->stream->pacing_rate != ~0U) { log_perror("setsockopt(SO_MAX_PACING_RATE)"); @@ -612,10 +606,6 @@ void Server::close_client(Client *client) if (client->stream != NULL) { delete_from(&client->stream->sleeping_clients, client); delete_from(&client->stream->to_process, client); - if (client->stream->mark_pool != NULL) { - int fwmark = client->fwmark; - client->stream->mark_pool->release_mark(fwmark); - } } // Log to access_log.