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.
This commit is contained in:
parent
48bab5a54f
commit
3a9e3b1757
|
@ -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
|
||||
)
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "util.hh"
|
||||
|
||||
#include <thread>
|
||||
|
||||
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;
|
|
@ -15,18 +15,30 @@ uvgrtp::holepuncher::holepuncher(std::shared_ptr<uvgrtp::socket> 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<std::thread> (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;
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "uvgrtp/runner.hh"
|
||||
#include "uvgrtp/util.hh"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
namespace uvgrtp {
|
||||
|
||||
class socket;
|
||||
|
||||
class holepuncher : public runner {
|
||||
class holepuncher {
|
||||
public:
|
||||
holepuncher(std::shared_ptr<uvgrtp::socket> socket);
|
||||
~holepuncher();
|
||||
|
@ -33,6 +33,9 @@ namespace uvgrtp {
|
|||
|
||||
std::shared_ptr<uvgrtp::socket> socket_;
|
||||
std::atomic<uint64_t> last_dgram_sent_;
|
||||
|
||||
bool active_;
|
||||
std::unique_ptr<std::thread> runner_;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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_;
|
||||
}
|
Loading…
Reference in New Issue