From 3a9e3b175774ed43a600ff178e11d875ad4513c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Thu, 3 Mar 2022 13:38:41 +0200 Subject: [PATCH] common: Remove runner class as it is not needed Integrated runner into holepuncher since it was the only remaining class still using it and they both are small classes where separation does more harm than good. --- CMakeLists.txt | 2 -- include/uvgrtp/runner.hh | 24 ------------------------ src/holepuncher.cc | 20 ++++++++++++++++---- src/holepuncher.hh | 7 +++++-- src/runner.cc | 33 --------------------------------- 5 files changed, 21 insertions(+), 65 deletions(-) delete mode 100644 include/uvgrtp/runner.hh delete mode 100644 src/runner.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cda2b2..6d7f5ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ target_sources(${PROJECT_NAME} PRIVATE src/random.cc src/rtcp.cc src/rtp.cc - src/runner.cc src/session.cc src/socket.cc src/zrtp.cc @@ -117,7 +116,6 @@ target_sources(${PROJECT_NAME} PRIVATE include/uvgrtp/lib.hh include/uvgrtp/media_stream.hh include/uvgrtp/rtcp.hh - include/uvgrtp/runner.hh include/uvgrtp/session.hh include/uvgrtp/socket.hh ) diff --git a/include/uvgrtp/runner.hh b/include/uvgrtp/runner.hh deleted file mode 100644 index c38359b..0000000 --- a/include/uvgrtp/runner.hh +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "util.hh" - -#include - -namespace uvgrtp { - class runner { - public: - runner(); - virtual ~runner(); - - virtual rtp_error_t start(); - virtual rtp_error_t stop(); - - virtual bool active(); - - protected: - bool active_; - std::thread *runner_; - }; -} - -namespace uvg_rtp = uvgrtp; diff --git a/src/holepuncher.cc b/src/holepuncher.cc index 31e2e6c..5f4a3b4 100644 --- a/src/holepuncher.cc +++ b/src/holepuncher.cc @@ -15,18 +15,30 @@ uvgrtp::holepuncher::holepuncher(std::shared_ptr socket): uvgrtp::holepuncher::~holepuncher() { + active_ = false; + + if (runner_ != nullptr) + { + if (runner_->joinable()) + { + runner_->join(); + } + runner_ = nullptr; + } } rtp_error_t uvgrtp::holepuncher::start() { - runner_ = new std::thread(&uvgrtp::holepuncher::keepalive, this); + runner_ = std::unique_ptr (new std::thread(&uvgrtp::holepuncher::keepalive, this)); runner_->detach(); - return uvgrtp::runner::start(); + active_ = true; + return RTP_OK; } rtp_error_t uvgrtp::holepuncher::stop() { - return uvgrtp::runner::stop(); + active_ = false; + return RTP_OK; } void uvgrtp::holepuncher::notify() @@ -36,7 +48,7 @@ void uvgrtp::holepuncher::notify() void uvgrtp::holepuncher::keepalive() { - while (active()) { + while (active_) { if (uvgrtp::clock::ntp::diff_now(last_dgram_sent_) < THRESHOLD) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); continue; diff --git a/src/holepuncher.hh b/src/holepuncher.hh index 81b724b..de4f426 100644 --- a/src/holepuncher.hh +++ b/src/holepuncher.hh @@ -1,16 +1,16 @@ #pragma once -#include "uvgrtp/runner.hh" #include "uvgrtp/util.hh" #include #include +#include namespace uvgrtp { class socket; - class holepuncher : public runner { + class holepuncher { public: holepuncher(std::shared_ptr socket); ~holepuncher(); @@ -33,6 +33,9 @@ namespace uvgrtp { std::shared_ptr socket_; std::atomic last_dgram_sent_; + + bool active_; + std::unique_ptr runner_; }; } diff --git a/src/runner.cc b/src/runner.cc deleted file mode 100644 index 0d91bf2..0000000 --- a/src/runner.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include "uvgrtp/runner.hh" - -uvgrtp::runner::runner(): - active_(false), runner_(nullptr) -{ -} - -uvgrtp::runner::~runner() -{ - active_ = false; - - if (runner_) - delete runner_; -} - -rtp_error_t uvgrtp::runner::start() -{ - active_ = true; - - return RTP_OK; -} - -rtp_error_t uvgrtp::runner::stop() -{ - active_ = false; - - return RTP_OK; -} - -bool uvgrtp::runner::active() -{ - return active_; -}