Use nullptr instead of NULL everywhere.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Apr 2018 07:48:46 +0000 (09:48 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Apr 2018 07:48:46 +0000 (09:48 +0200)
19 files changed:
acceptor.cpp
accesslog.cpp
accesslog.h
client.cpp
config.cpp
httpinput.cpp
input.cpp
input.h
input_stats.cpp
log.cpp
main.cpp
parse.cpp
server.cpp
serverpool.cpp
stats.cpp
stream.cpp
thread.cpp
thread.h
udpinput.cpp

index bb3ebcb..29a7f8c 100644 (file)
@@ -130,7 +130,7 @@ void Acceptor::close_socket()
 void Acceptor::do_work()
 {
        while (!should_stop()) {
-               if (!wait_for_activity(server_sock, POLLIN, NULL)) {
+               if (!wait_for_activity(server_sock, POLLIN, nullptr)) {
                        continue;
                }
 
index af53872..4a54fdb 100644 (file)
@@ -14,12 +14,12 @@ using namespace std;
 
 AccessLogThread::AccessLogThread()
 {
-       pthread_mutex_init(&mutex, NULL);
+       pthread_mutex_init(&mutex, nullptr);
 }
 
 AccessLogThread::AccessLogThread(const string &filename)
        : filename(filename) {
-       pthread_mutex_init(&mutex, NULL);
+       pthread_mutex_init(&mutex, nullptr);
 }
 
 void AccessLogThread::write(const ClientStats& client)
@@ -35,10 +35,10 @@ void AccessLogThread::do_work()
 {
        // Open the file.
        if (filename.empty()) {
-               logfp = NULL;
+               logfp = nullptr;
        } else {
                logfp = fopen(filename.c_str(), "a+");
-               if (logfp == NULL) {
+               if (logfp == nullptr) {
                        log_perror(filename.c_str());
                        // Continue as before.
                }
@@ -52,7 +52,7 @@ void AccessLogThread::do_work()
                        swap(pending_writes, writes);
                }
 
-               if (logfp != NULL) {
+               if (logfp != nullptr) {
                        // Do the actual writes.
                        timespec now_monotonic;
                        timespec now_realtime;
@@ -82,14 +82,14 @@ void AccessLogThread::do_work()
 
                // Wait until we are being woken up, either to quit or because
                // there is material in pending_writes.
-               wait_for_wakeup(NULL);
+               wait_for_wakeup(nullptr);
        }
 
-       if (logfp != NULL) {    
+       if (logfp != nullptr) { 
                if (fclose(logfp) == EOF) {
                        log_perror("fclose");
                }
        }
 
-       logfp = NULL;
+       logfp = nullptr;
 }
index 0ef5c75..9eae365 100644 (file)
@@ -29,7 +29,7 @@ public:
 private:
        virtual void do_work();
 
-       // The file we are logging to. If NULL, do not log.
+       // The file we are logging to. If nullptr, do not log.
        FILE *logfp;
        std::string filename;
 
index 7c58d51..3fdd817 100644 (file)
@@ -18,14 +18,14 @@ using namespace std;
 Client::Client(int sock)
        : sock(sock),
          state(Client::READING_REQUEST),
-         stream(NULL),
+         stream(nullptr),
          header_or_short_response_bytes_sent(0),
          stream_pos(0),
          bytes_sent(0),
          bytes_lost(0),
          num_loss_events(0),
-         tls_context(NULL),
-         tls_data_to_send(NULL),
+         tls_context(nullptr),
+         tls_data_to_send(nullptr),
          tls_data_left_to_send(0),
          in_ktls_mode(false)
 {
@@ -49,14 +49,14 @@ Client::Client(int sock)
        char buf[INET6_ADDRSTRLEN];
        if (IN6_IS_ADDR_V4MAPPED(&addr.sin6_addr)) {
                // IPv4 address, really.
-               if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == NULL) {
+               if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == nullptr) {
                        log_perror("inet_ntop");
                        remote_addr = "";
                } else {
                        remote_addr = buf;
                }
        } else {
-               if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == NULL) {
+               if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == nullptr) {
                        log_perror("inet_ntop");
                        remote_addr = "";
                } else {
@@ -81,7 +81,7 @@ Client::Client(const ClientProto &serialized, Stream *stream)
          bytes_lost(serialized.bytes_lost()),
          num_loss_events(serialized.num_loss_events())
 {
-       if (stream != NULL) {
+       if (stream != nullptr) {
                if (setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, &stream->pacing_rate, sizeof(stream->pacing_rate)) == -1) {
                        if (stream->pacing_rate != ~0U) {
                                log_perror("setsockopt(SO_MAX_PACING_RATE)");
@@ -96,7 +96,7 @@ Client::Client(const ClientProto &serialized, Stream *stream)
                tls_context = tls_import_context(
                        reinterpret_cast<const unsigned char *>(serialized.tls_context().data()),
                        serialized.tls_context().size());
-               if (tls_context == NULL) {
+               if (tls_context == nullptr) {
                        log(WARNING, "tls_import_context() failed, TLS client might not survive across restart");
                } else {
                        tls_data_to_send = tls_get_write_buffer(tls_context, &tls_data_left_to_send);
@@ -104,7 +104,7 @@ Client::Client(const ClientProto &serialized, Stream *stream)
                        assert(serialized.tls_output_bytes_already_consumed() <= tls_data_left_to_send);
                        if (serialized.tls_output_bytes_already_consumed() >= tls_data_left_to_send) {
                                tls_buffer_clear(tls_context);
-                               tls_data_to_send = NULL;
+                               tls_data_to_send = nullptr;
                        } else {
                                tls_data_to_send += serialized.tls_output_bytes_already_consumed();
                                tls_data_left_to_send -= serialized.tls_output_bytes_already_consumed();
@@ -112,7 +112,7 @@ Client::Client(const ClientProto &serialized, Stream *stream)
                        in_ktls_mode = serialized.in_ktls_mode();
                }
        } else {
-               tls_context = NULL;
+               tls_context = nullptr;
        }
 }
 
@@ -135,9 +135,9 @@ ClientProto Client::serialize() const
        serialized.set_bytes_lost(bytes_lost);
        serialized.set_num_loss_events(num_loss_events);
 
-       if (tls_context != NULL) {
+       if (tls_context != nullptr) {
                bool small_version = false;
-               int required_size = tls_export_context(tls_context, NULL, 0, small_version);
+               int required_size = tls_export_context(tls_context, nullptr, 0, small_version);
                if (required_size <= 0) {
                        // Can happen if we're in the middle of the key exchange, unfortunately.
                        // We'll get an error fairly fast, and this client hasn't started playing
@@ -164,8 +164,8 @@ ClientProto Client::serialize() const
                        // currently serialize in-progress key exchanges.
                        unsigned base_tls_data_left_to_send;
                        const unsigned char *base_tls_data_to_send = tls_get_write_buffer(tls_context, &base_tls_data_left_to_send);
-                       if (base_tls_data_to_send == NULL) {
-                               assert(tls_data_to_send == NULL);
+                       if (base_tls_data_to_send == nullptr) {
+                               assert(tls_data_to_send == nullptr);
                        } else {
                                assert(tls_data_to_send + tls_data_left_to_send == base_tls_data_to_send + base_tls_data_left_to_send);
                        }
index 0573f54..55968ee 100644 (file)
@@ -89,14 +89,14 @@ bool parse_hostport(const string &hostport, sockaddr_in6 *addr)
 bool read_config(const string &filename, vector<ConfigLine> *lines)
 {
        FILE *fp = fopen(filename.c_str(), "r");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                log_perror(filename.c_str());
                return false;
        }
 
        char buf[4096];
        while (!feof(fp)) {
-               if (fgets(buf, sizeof(buf), fp) == NULL) {
+               if (fgets(buf, sizeof(buf), fp) == nullptr) {
                        break;
                }
 
@@ -181,7 +181,7 @@ bool load_file_to_string(const string &filename, size_t max_size, string *conten
        contents->clear();
 
        FILE *fp = fopen(filename.c_str(), "r");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                log_perror(filename.c_str());
                return false;
        }
index c0cfc03..5b74319 100644 (file)
@@ -55,7 +55,7 @@ HTTPInput::HTTPInput(const string &url, Input::Encoding encoding)
          num_connection_attempts(0),
          suppress_logging(false)
 {
-       pthread_mutex_init(&stats_mutex, NULL);
+       pthread_mutex_init(&stats_mutex, nullptr);
        stats.url = url;
        stats.bytes_received = 0;
        stats.data_bytes_received = 0;
@@ -89,7 +89,7 @@ HTTPInput::HTTPInput(const InputProto &serialized)
        string protocol, user;
        parse_url(url, &protocol, &user, &host, &port, &path);  // Don't care if it fails.
 
-       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();
@@ -97,7 +97,7 @@ HTTPInput::HTTPInput(const InputProto &serialized)
        if (serialized.has_connect_time()) {
                stats.connect_time = serialized.connect_time();
        } else {
-               stats.connect_time = time(NULL);
+               stats.connect_time = time(nullptr);
        }
        if (serialized.has_latency_sec()) {
                stats.latency_sec = serialized.latency_sec();
@@ -151,7 +151,7 @@ InputProto HTTPInput::serialize() const
 int HTTPInput::lookup_and_connect(const string &host, const string &port)
 {
        addrinfo *ai;
-       int err = getaddrinfo(host.c_str(), port.c_str(), NULL, &ai);
+       int err = getaddrinfo(host.c_str(), port.c_str(), nullptr, &ai);
        if (err != 0) {
                if (!suppress_logging) {
                        log(WARNING, "[%s] Lookup of '%s' failed (%s).",
@@ -194,7 +194,7 @@ int HTTPInput::lookup_and_connect(const string &host, const string &port)
 
                // Wait for the connect to complete, or an error to happen.
                for ( ;; ) {
-                       bool complete = wait_for_activity(sock, POLLIN | POLLOUT, NULL);
+                       bool complete = wait_for_activity(sock, POLLIN | POLLOUT, nullptr);
                        if (should_stop()) {
                                safe_close(sock);
                                return -1;
@@ -406,7 +406,7 @@ void HTTPInput::do_work()
                                }
 
                                MutexLock lock(&stats_mutex);
-                               stats.connect_time = time(NULL);
+                               stats.connect_time = time(nullptr);
                                clock_gettime(CLOCK_MONOTONIC_COARSE, &last_activity);
                        }
                        break;
@@ -474,7 +474,7 @@ void HTTPInput::do_work()
                        if (status == RP_EXTRA_DATA) {
                                char *ptr = static_cast<char *>(
                                        memmem(response.data(), response.size(), "\r\n\r\n", 4));
-                               assert(ptr != NULL);
+                               assert(ptr != nullptr);
                                extra_data = string(ptr + 4, &response[0] + response.size());
                                response.resize(ptr - response.data());
                        }
@@ -601,7 +601,7 @@ void HTTPInput::process_data(char *ptr, size_t bytes)
                        char *ptr = static_cast<char *>(
                                memmem(pending_data.data(), pending_data.size(),
                                       METACUBE2_SYNC, strlen(METACUBE2_SYNC)));
-                       if (ptr == NULL) {
+                       if (ptr == nullptr) {
                                // OK, so we didn't find the sync marker. We know then that
                                // we do not have the _full_ marker in the buffer, but we
                                // could have N-1 bytes. Drop everything before that,
index 7f95b26..b434eed 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -98,7 +98,7 @@ Input *create_input(const string &url, Input::Encoding encoding)
 {
        string protocol, user, host, port, path;
        if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
-               return NULL;
+               return nullptr;
        }
        if (protocol == "http") {
                return new HTTPInput(url, encoding);
@@ -107,14 +107,14 @@ Input *create_input(const string &url, Input::Encoding encoding)
                // encoding is ignored; it's never Metacube.
                return new UDPInput(url);
        }
-       return NULL;
+       return nullptr;
 }
 
 Input *create_input(const InputProto &serialized)
 {
        string protocol, user, host, port, path;
        if (!parse_url(serialized.url(), &protocol, &user, &host, &port, &path)) {
-               return NULL;
+               return nullptr;
        }
        if (protocol == "http") {
                return new HTTPInput(serialized);
@@ -122,7 +122,7 @@ Input *create_input(const InputProto &serialized)
        if (protocol == "udp") {
                return new UDPInput(serialized);
        }
-       return NULL;
+       return nullptr;
 }
 
 Input::~Input() {}
diff --git a/input.h b/input.h
index d609fdf..7e67392 100644 (file)
--- a/input.h
+++ b/input.h
@@ -58,7 +58,7 @@ public:
 bool parse_url(const std::string &url, std::string *protocol, std::string *user, std::string *host, std::string *port, std::string *path);
 
 // Figure out the right type of input based on the URL, and create a new Input of the right type.
-// Will return NULL if unknown.
+// Will return nullptr if unknown.
 Input *create_input(const std::string &url, Input::Encoding encoding);
 Input *create_input(const InputProto &serialized);
 
index 6bd1529..f909113 100644 (file)
@@ -39,7 +39,7 @@ void InputStatsThread::do_work()
                }
 
                fp = fdopen(fd, "w");
-               if (fp == NULL) {
+               if (fp == nullptr) {
                        log_perror("fdopen");
                        safe_close(fd);
                        if (unlink(filename) == -1) {
@@ -49,7 +49,7 @@ void InputStatsThread::do_work()
                        goto sleep;
                }
 
-               now = time(NULL);
+               now = time(nullptr);
                for (size_t i = 0; i < inputs.size(); ++i) {
                        InputStats stats = inputs[i]->get_stats();
                        fprintf(fp, "%s %llu %llu", stats.url.c_str(),
diff --git a/log.cpp b/log.cpp
index 417b544..198ceae 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -16,7 +16,7 @@
 using namespace std;
 
 // Yes, it's a bit ugly.
-#define SYSLOG_FAKE_FILE (static_cast<FILE *>(NULL))
+#define SYSLOG_FAKE_FILE (static_cast<FILE *>(nullptr))
 
 bool logging_started = false;
 vector<FILE *> log_destinations;
@@ -24,7 +24,7 @@ vector<FILE *> log_destinations;
 void add_log_destination_file(const string &filename)
 {
        FILE *fp = fopen(filename.c_str(), "a");
-       if (fp == NULL) {
+       if (fp == nullptr) {
                perror(filename.c_str());
                return;
        }
@@ -71,11 +71,11 @@ void log(LogLevel log_level, const char *fmt, ...)
        vsnprintf(formatted_msg, sizeof(formatted_msg), fmt, ap);
        va_end(ap);
 
-       time_t now = time(NULL);
+       time_t now = time(nullptr);
        struct tm lt;
        struct tm *ltime = localtime_r(&now, &lt);
        char timestamp[1024];
-       if (ltime == NULL) {
+       if (ltime == nullptr) {
                strcpy(timestamp, "???");
        } else {
                strftime(timestamp, sizeof(timestamp), "%a, %d %b %Y %T %z", ltime);
index c208b2d..c048878 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -36,8 +36,8 @@
 
 using namespace std;
 
-AccessLogThread *access_log = NULL;
-ServerPool *servers = NULL;
+AccessLogThread *access_log = nullptr;
+ServerPool *servers = nullptr;
 volatile bool hupped = false;
 volatile bool stopped = false;
 
@@ -116,7 +116,7 @@ vector<Acceptor *> create_acceptors(
 {
        vector<Acceptor *> acceptors;
        for (const AcceptorConfig &acceptor_config : config.acceptors) {
-               Acceptor *acceptor = NULL;
+               Acceptor *acceptor = nullptr;
                const auto deserialized_acceptor_it = deserialized_acceptors->find(acceptor_config);
                if (deserialized_acceptor_it != deserialized_acceptors->end()) {
                        acceptor = deserialized_acceptor_it->second;
@@ -152,7 +152,7 @@ void create_config_input(const string &src, Input::Encoding encoding, multimap<I
 
        InputWithRefcount iwr;
        iwr.input = create_input(src, encoding);
-       if (iwr.input == NULL) {
+       if (iwr.input == nullptr) {
                log(ERROR, "did not understand URL '%s' or source encoding was invalid, clients will not get any data.",
                        src.c_str());
                return;
@@ -282,7 +282,7 @@ bool dry_run_config(const string &argv0, const string &config_filename)
                return false;
        case 0:
                // Child.
-               execlp(argv0_copy, argv0_copy, "--test-config", config_filename_copy, NULL);
+               execlp(argv0_copy, argv0_copy, "--test-config", config_filename_copy, nullptr);
                log_perror(argv0_copy);
                _exit(1);
        default:
@@ -363,11 +363,11 @@ int main(int argc, char **argv)
        char argv0_canon[PATH_MAX];
        char config_filename_canon[PATH_MAX];
 
-       if (realpath("/proc/self/exe", argv0_canon) == NULL) {
+       if (realpath("/proc/self/exe", argv0_canon) == nullptr) {
                log_perror(argv[0]);
                exit(1);
        }
-       if (realpath(config_filename.c_str(), config_filename_canon) == NULL) {
+       if (realpath(config_filename.c_str(), config_filename_canon) == nullptr) {
                log_perror(config_filename.c_str());
                exit(1);
        }
@@ -573,11 +573,11 @@ start:
        err = clock_gettime(CLOCK_MONOTONIC, &serialize_start);
        assert(err != -1);
 
-       if (input_stats_thread != NULL) {
+       if (input_stats_thread != nullptr) {
                input_stats_thread->stop();
                input_stats_thread.reset();
        }
-       if (stats_thread != NULL) {
+       if (stats_thread != nullptr) {
                stats_thread->stop();
                stats_thread.reset();
        }
@@ -626,7 +626,7 @@ start:
        sprintf(buf, "%d", state_fd);
 
        for ( ;; ) {
-               execlp(argv0_canon, argv0_canon, config_filename_canon, "--state", buf, NULL);
+               execlp(argv0_canon, argv0_canon, config_filename_canon, "--state", buf, nullptr);
                open_logs(config.log_destinations);
                log_perror("execlp");
                log(ERROR, "re-exec of %s failed. Waiting 0.2 seconds and trying again...", argv0_canon);
index 37b5436..f4c78fc 100644 (file)
--- a/parse.cpp
+++ b/parse.cpp
@@ -100,7 +100,7 @@ RequestParseStatus wait_for_double_newline(string *existing_data, const char *ne
        const char *ptr = reinterpret_cast<char *>(
                memmem(existing_data->data() + start_at, existing_data->size() - start_at,
                       "\r\n\r\n", 4));
-       if (ptr == NULL) {
+       if (ptr == nullptr) {
                return RP_NOT_FINISHED_YET;
        }
        if (ptr != existing_data->data() + existing_data->size() - 4) {
index 0b4d076..2ec2fe0 100644 (file)
@@ -57,8 +57,8 @@ inline bool is_earlier(timespec a, timespec b)
 
 Server::Server()
 {
-       pthread_mutex_init(&mutex, NULL);
-       pthread_mutex_init(&queued_clients_mutex, NULL);
+       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) {
@@ -241,7 +241,7 @@ void Server::add_client(int sock, Acceptor *acceptor)
        if (is_tls) {
                assert(tls_server_contexts.count(acceptor));
                client_ptr->tls_context = tls_accept(tls_server_contexts[acceptor]);
-               if (client_ptr->tls_context == NULL) {
+               if (client_ptr->tls_context == nullptr) {
                        log(ERROR, "tls_accept() failed");
                        close_client(client_ptr);
                        return;
@@ -259,7 +259,7 @@ void Server::add_client_from_serialized(const ClientProto &client)
        int stream_index = lookup_stream_by_url(client.url());
        if (stream_index == -1) {
                assert(client.state() != Client::SENDING_DATA);
-               stream = NULL;
+               stream = nullptr;
        } else {
                stream = streams[stream_index].get();
        }
@@ -418,7 +418,7 @@ void Server::process_client(Client *client)
 {
        switch (client->state) {
        case Client::READING_REQUEST: {
-               if (client->tls_context != NULL) {
+               if (client->tls_context != nullptr) {
                        if (send_pending_tls_data(client)) {
                                // send_pending_tls_data() hit postconditions #1 or #4.
                                return;
@@ -429,7 +429,7 @@ read_request_again:
                // Try to read more of the request.
                char buf[1024];
                int ret;
-               if (client->tls_context == NULL) {
+               if (client->tls_context == nullptr) {
                        ret = read_nontls_data(client, buf, sizeof(buf));
                        if (ret == -1) {
                                // read_nontls_data() hit postconditions #1 or #2.
@@ -661,9 +661,9 @@ sending_data_again:
 bool Server::send_pending_tls_data(Client *client)
 {
        // See if there's data from the TLS library to write.
-       if (client->tls_data_to_send == NULL) {
+       if (client->tls_data_to_send == nullptr) {
                client->tls_data_to_send = tls_get_write_buffer(client->tls_context, &client->tls_data_left_to_send);
-               if (client->tls_data_to_send == NULL) {
+               if (client->tls_data_to_send == nullptr) {
                        // Really no data to send.
                        return false;
                }
@@ -692,7 +692,7 @@ send_data_again:
        if (ret > 0 && size_t(ret) == client->tls_data_left_to_send) {
                // All data has been sent, so we don't need to go to sleep.
                tls_buffer_clear(client->tls_context);
-               client->tls_data_to_send = NULL;
+               client->tls_data_to_send = nullptr;
                return false;
        }
 
@@ -790,7 +790,7 @@ read_again:
 void Server::skip_lost_data(Client *client)
 {
        Stream *stream = client->stream;
-       if (stream == NULL) {
+       if (stream == nullptr) {
                return;
        }
        size_t bytes_to_send = stream->bytes_received - client->stream_pos;
@@ -939,13 +939,13 @@ void delete_from(vector<T> *v, T elem)
        
 void Server::close_client(Client *client)
 {
-       if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->sock, NULL) == -1) {
+       if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->sock, nullptr) == -1) {
                log_perror("epoll_ctl(EPOLL_CTL_DEL)");
                exit(1);
        }
 
        // This client could be sleeping, so we'll need to fix that. (Argh, O(n).)
-       if (client->stream != NULL) {
+       if (client->stream != nullptr) {
                delete_from(&client->stream->sleeping_clients, client);
                delete_from(&client->stream->to_process, client);
        }
index 1414d21..232ccea 100644 (file)
@@ -60,7 +60,7 @@ void ServerPool::add_client_from_serialized(const ClientProto &client)
 
 int ServerPool::lookup_stream_by_url(const string &url) const
 {
-       assert(servers != NULL);
+       assert(servers != nullptr);
        return servers[0].lookup_stream_by_url(url);
 }
 
index 661a17b..5193243 100644 (file)
--- a/stats.cpp
+++ b/stats.cpp
@@ -47,7 +47,7 @@ void StatsThread::do_work()
                }
 
                fp = fdopen(fd, "w");
-               if (fp == NULL) {
+               if (fp == nullptr) {
                        log_perror("fdopen");
                        safe_close(fd);
                        if (unlink(filename) == -1) {
index 734110c..f5abbfd 100644 (file)
@@ -34,7 +34,7 @@ Stream::Stream(const string &url, size_t backlog_size, size_t prebuffering_bytes
                exit(1);
        }
 
-       pthread_mutex_init(&queued_data_mutex, NULL);
+       pthread_mutex_init(&queued_data_mutex, nullptr);
 }
 
 Stream::~Stream()
@@ -69,7 +69,7 @@ Stream::Stream(const StreamProto &serialized, int data_fd)
                suitable_starting_points.push_back(point);
        }
 
-       pthread_mutex_init(&queued_data_mutex, NULL);
+       pthread_mutex_init(&queued_data_mutex, nullptr);
 }
 
 StreamProto Stream::serialize()
index 72bc320..473c71a 100644 (file)
@@ -14,9 +14,9 @@ Thread::~Thread() {}
 
 void Thread::run()
 {
-       pthread_mutex_init(&should_stop_mutex, NULL);
+       pthread_mutex_init(&should_stop_mutex, nullptr);
        should_stop_status = false;
-       pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this);
+       pthread_create(&worker_thread, nullptr, &Thread::do_work_thunk, this);
 }
 
 void Thread::stop()
@@ -26,7 +26,7 @@ void Thread::stop()
                should_stop_status = true;
        }
        wakeup();
-       if (pthread_join(worker_thread, NULL) == -1) {
+       if (pthread_join(worker_thread, nullptr) == -1) {
                log_perror("pthread_join");
                exit(1);
        }
@@ -42,7 +42,7 @@ void *Thread::do_work_thunk(void *arg)
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set, SIGHUP);
-       int err = pthread_sigmask(SIG_BLOCK, &set, NULL);
+       int err = pthread_sigmask(SIG_BLOCK, &set, nullptr);
        if (err != 0) {
                errno = err;
                log_perror("pthread_sigmask");
@@ -61,7 +61,7 @@ void *Thread::do_work_thunk(void *arg)
 
        // Call the right thunk.
        thread->do_work();
-       return NULL;
+       return nullptr;
 }
 
 bool Thread::wait_for_activity(int fd, short events, const struct timespec *timeout_ts)
index 728df27..09e2754 100644 (file)
--- a/thread.h
+++ b/thread.h
@@ -32,7 +32,7 @@ protected:
        // the file descriptor.
        //
        // If fd is -1, wait until a wakeup or timeout.
-       // if timeout_ts is NULL, there is no timeout.
+       // if timeout_ts is nullptr, there is no timeout.
        bool wait_for_activity(int fd, short events, const timespec *timeout_ts);
 
        // Wait until a wakeup.
index dada7b0..445d4f5 100644 (file)
@@ -113,12 +113,12 @@ 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.metadata_bytes_received = 0;
-       stats.connect_time = time(NULL);
+       stats.connect_time = time(nullptr);
        stats.latency_sec = HUGE_VAL;
 }
 
@@ -133,14 +133,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);
        }
 }
 
@@ -206,7 +206,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;