]> git.sesse.net Git - cubemap/blobdiff - udpinput.cpp
Use in-class initialization for making it harder to forget to set a default.
[cubemap] / udpinput.cpp
index 71364f1e79d2e98084b4c0b358fbd11c06c59f1c..93eaaa76801c0dbab7383e2e7b8902b5fd408ea0 100644 (file)
@@ -6,6 +6,7 @@
 #include <sys/socket.h>
 #include <time.h>
 #include <unistd.h>
+#include <math.h>
 #include <string>
 
 #include "acceptor.h"
@@ -112,11 +113,9 @@ UDPInput::UDPInput(const string &url)
 
        construct_header();
 
-       pthread_mutex_init(&stats_mutex, NULL);
+       pthread_mutex_init(&stats_mutex, nullptr);
        stats.url = url;
-       stats.bytes_received = 0;
-       stats.data_bytes_received = 0;
-       stats.connect_time = time(NULL);
+       stats.connect_time = time(nullptr);
 }
 
 UDPInput::UDPInput(const InputProto &serialized)
@@ -130,14 +129,14 @@ UDPInput::UDPInput(const InputProto &serialized)
 
        construct_header();
 
-       pthread_mutex_init(&stats_mutex, NULL);
+       pthread_mutex_init(&stats_mutex, nullptr);
        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);
        }
 }
 
@@ -149,6 +148,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;
 }
 
@@ -202,7 +202,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;
@@ -224,9 +224,9 @@ void UDPInput::do_work()
                        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);
                }
        }
 }