X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=udpinput.cpp;h=e444bbc09aa56e3231f9c8f06debad62386856fd;hp=048866a6ba5d21a92a88dbff08ba37d0f07eb35e;hb=bd694fdd3dd1417399aecead2c8b91fc4fe95ce8;hpb=4a33511c426ae90abb261f09fda1e31e0c30ca16 diff --git a/udpinput.cpp b/udpinput.cpp index 048866a..e444bbc 100644 --- a/udpinput.cpp +++ b/udpinput.cpp @@ -9,6 +9,7 @@ #include "acceptor.h" #include "log.h" +#include "mutexlock.h" #include "serverpool.h" #include "state.pb.h" #include "udpinput.h" @@ -29,6 +30,11 @@ UDPInput::UDPInput(const string &url) assert(ok); construct_header(); + + pthread_mutex_init(&stats_mutex, NULL); + stats.url = url; + stats.bytes_received = 0; + stats.data_bytes_received = 0; } UDPInput::UDPInput(const InputProto &serialized) @@ -41,6 +47,11 @@ UDPInput::UDPInput(const InputProto &serialized) assert(ok); 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(); } InputProto UDPInput::serialize() const @@ -48,6 +59,8 @@ InputProto UDPInput::serialize() const InputProto serialized; serialized.set_url(url); serialized.set_sock(sock); + serialized.set_bytes_received(stats.bytes_received); + serialized.set_data_bytes_received(stats.data_bytes_received); return serialized; } @@ -104,9 +117,21 @@ void UDPInput::do_work() close_socket(); continue; } + + { + MutexLock 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, SUITABLE_FOR_STREAM_START); } } } + +InputStats UDPInput::get_stats() const +{ + MutexLock lock(&stats_mutex); + return stats; +}