X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=udpinput.cpp;h=0035640ad4a91bd6ed2d4d59f3a6db8feb677a6d;hp=81aef7f9c9bbae265b832f9fd8f1ba353c311c8a;hb=50651c954803c1941e6ad1bb494712891c18f7d2;hpb=b05c2965d3d5bfc4f24f17a27716a69ddf03a3cc diff --git a/udpinput.cpp b/udpinput.cpp index 81aef7f..0035640 100644 --- a/udpinput.cpp +++ b/udpinput.cpp @@ -11,7 +11,6 @@ #include "acceptor.h" #include "log.h" -#include "mutexlock.h" #include "serverpool.h" #include "state.pb.h" #include "stream.h" @@ -113,13 +112,8 @@ UDPInput::UDPInput(const string &url) construct_header(); - pthread_mutex_init(&stats_mutex, NULL); stats.url = url; - stats.bytes_received = 0; - stats.data_bytes_received = 0; - stats.metadata_bytes_received = 0; - stats.connect_time = time(NULL); - stats.latency_sec = HUGE_VAL; + stats.connect_time = time(nullptr); } UDPInput::UDPInput(const InputProto &serialized) @@ -133,14 +127,13 @@ UDPInput::UDPInput(const InputProto &serialized) construct_header(); - pthread_mutex_init(&stats_mutex, NULL); stats.url = url; stats.bytes_received = serialized.bytes_received(); stats.data_bytes_received = serialized.data_bytes_received(); if (serialized.has_connect_time()) { stats.connect_time = serialized.connect_time(); } else { - stats.connect_time = time(NULL); + stats.connect_time = time(nullptr); } } @@ -152,6 +145,7 @@ InputProto UDPInput::serialize() const serialized.set_bytes_received(stats.bytes_received); serialized.set_data_bytes_received(stats.data_bytes_received); serialized.set_connect_time(stats.connect_time); + serialized.set_is_metacube_encoded(false); return serialized; } @@ -205,7 +199,7 @@ void UDPInput::do_work() } // Wait for a packet, or a wakeup. - bool activity = wait_for_activity(sock, POLLIN, NULL); + bool activity = wait_for_activity(sock, POLLIN, nullptr); if (!activity) { // Most likely, should_stop was set. continue; @@ -223,19 +217,19 @@ void UDPInput::do_work() } { - MutexLock lock(&stats_mutex); + lock_guard lock(stats_mutex); stats.bytes_received += ret; stats.data_bytes_received += ret; } - - for (size_t i = 0; i < stream_indices.size(); ++i) { - servers->add_data(stream_indices[i], packet_buf, ret, /*metacube_flags=*/0); + + for (size_t stream_index : stream_indices) { + servers->add_data(stream_index, packet_buf, ret, /*metacube_flags=*/0); } } } InputStats UDPInput::get_stats() const { - MutexLock lock(&stats_mutex); + lock_guard lock(stats_mutex); return stats; }