From 03aa5e41125169733558854aa7a527f73c2adcc6 Mon Sep 17 00:00:00 2001 From: Sektor van Skijlen Date: Fri, 8 Mar 2024 14:50:16 +0100 Subject: [PATCH] [core] Formal errors fixed (#2907). --- apps/verbose.hpp | 2 +- srtcore/logging.h | 14 +++++----- srtcore/utilities.h | 3 ++- testing/srt-test-mpbond.cpp | 7 ++--- testing/srt-test-relay.cpp | 1 + testing/testactivemedia.cpp | 3 +++ testing/testactivemedia.hpp | 12 ++++----- testing/testmedia.hpp | 52 ++++++++++++++++++------------------- 8 files changed, 49 insertions(+), 45 deletions(-) diff --git a/apps/verbose.hpp b/apps/verbose.hpp index 10591888b..879d54086 100644 --- a/apps/verbose.hpp +++ b/apps/verbose.hpp @@ -80,7 +80,7 @@ inline void Print(Log& ) {} template inline void Print(Log& out, Arg1&& arg1, Args&&... args) { - out << arg1; + out << std::forward(arg1); Print(out, args...); } diff --git a/srtcore/logging.h b/srtcore/logging.h index 3abfe0326..2ec5f46aa 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -203,16 +203,16 @@ struct SRT_API LogDispatcher template void PrintLogLine(const char* file, int line, const std::string& area, Args&&... args); - template - void operator()(Arg1&& arg1, Args&&... args) + template + void operator()(Args&&... args) { - PrintLogLine("UNKNOWN.c++", 0, "UNKNOWN", arg1, args...); + PrintLogLine("UNKNOWN.c++", 0, "UNKNOWN", args...); } - template - void printloc(const char* file, int line, const std::string& area, Arg1&& arg1, Args&&... args) + template + void printloc(const char* file, int line, const std::string& area, Args&&... args) { - PrintLogLine(file, line, area, arg1, args...); + PrintLogLine(file, line, area, args...); } #else template @@ -440,7 +440,7 @@ inline void PrintArgs(std::ostream&) {} template inline void PrintArgs(std::ostream& serr, Arg1&& arg1, Args&&... args) { - serr << arg1; + serr << std::forward(arg1); PrintArgs(serr, args...); } diff --git a/srtcore/utilities.h b/srtcore/utilities.h index 9b9288cac..8a1374eb7 100644 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -35,6 +35,7 @@ written by #include #include #include +#include #if HAVE_CXX11 #include @@ -575,7 +576,7 @@ inline Stream& Print(Stream& in) { return in;} template inline Stream& Print(Stream& sout, Arg1&& arg1, Args&&... args) { - sout << arg1; + sout << std::forward(arg1); return Print(sout, args...); } diff --git a/testing/srt-test-mpbond.cpp b/testing/srt-test-mpbond.cpp index 03066363a..bf9739675 100644 --- a/testing/srt-test-mpbond.cpp +++ b/testing/srt-test-mpbond.cpp @@ -42,6 +42,10 @@ srt_logging::Logger applog(SRT_LOGFA_APP, srt_logger_config, "srt-mpbond"); +using namespace srt; +using namespace std; + + volatile bool mpbond_int_state = false; void OnINT_SetIntState(int) { @@ -49,9 +53,6 @@ void OnINT_SetIntState(int) mpbond_int_state = true; } -using namespace srt; - - int main( int argc, char** argv ) { // This is mainly required on Windows to initialize the network system, diff --git a/testing/srt-test-relay.cpp b/testing/srt-test-relay.cpp index dfabef62b..45d657128 100755 --- a/testing/srt-test-relay.cpp +++ b/testing/srt-test-relay.cpp @@ -45,6 +45,7 @@ written by #include "threadname.h" +using namespace std; bool Upload(UriParser& srt, UriParser& file); diff --git a/testing/testactivemedia.cpp b/testing/testactivemedia.cpp index 7d062f49d..96344f0b2 100644 --- a/testing/testactivemedia.cpp +++ b/testing/testactivemedia.cpp @@ -1,6 +1,9 @@ #include "testactivemedia.hpp" +using namespace std; + + void SourceMedium::Runner() { srt::ThreadName::set("SourceRN"); diff --git a/testing/testactivemedia.hpp b/testing/testactivemedia.hpp index f4bc360ba..011dcbfe7 100644 --- a/testing/testactivemedia.hpp +++ b/testing/testactivemedia.hpp @@ -59,7 +59,7 @@ struct Medium std::ostringstream tns; tns << typeid(*this).name() << ":" << this; srt::ThreadName tn(tns.str()); - thr = thread( [this] { RunnerBase(); } ); + thr = std::thread( [this] { RunnerBase(); } ); } void quit() @@ -89,12 +89,12 @@ struct Medium if (Verbose::on) Verb() << VerbLock << "Medium " << this << " exited with Transmission Error:\n\t" << e.what(); else - cerr << "Transmission Error: " << e.what() << endl; + std::cerr << "Transmission Error: " << e.what() << std::endl; } catch (...) { if (Verbose::on) Verb() << VerbLock << "Medium " << this << " exited with UNKNOWN EXCEPTION:"; else - cerr << "UNKNOWN EXCEPTION on medium\n"; + std::cerr << "UNKNOWN EXCEPTION on medium\n"; } } @@ -150,7 +150,7 @@ struct TargetMedium: Medium bool Schedule(const MediaPacket& data) { LOGP(applog.Debug, "TargetMedium::Schedule LOCK ... "); - lock_guard lg(buffer_lock); + std::lock_guard lg(buffer_lock); LOGP(applog.Debug, "TargetMedium::Schedule LOCKED - checking: running=", running, " interrupt=", ::transmit_int_state); if (!running || ::transmit_int_state) { @@ -166,13 +166,13 @@ struct TargetMedium: Medium void Clear() { - lock_guard lg(buffer_lock); + std::lock_guard lg(buffer_lock); buffer.clear(); } void Interrupt() { - lock_guard lg(buffer_lock); + std::lock_guard lg(buffer_lock); running = false; ready.notify_one(); } diff --git a/testing/testmedia.hpp b/testing/testmedia.hpp index 337f5f365..be72471d1 100644 --- a/testing/testmedia.hpp +++ b/testing/testmedia.hpp @@ -29,8 +29,6 @@ extern std::atomic transmit_int_state; extern std::shared_ptr transmit_stats_writer; -using namespace std; - const srt_logging::LogFA SRT_LOGFA_APP = 10; extern srt_logging::Logger applog; @@ -57,7 +55,7 @@ class SrtCommon struct ConnectionBase { - string host; + std::string host; int port; int weight = 0; SRTSOCKET socket = SRT_INVALID_SOCK; @@ -65,7 +63,7 @@ class SrtCommon srt::sockaddr_any target; int token = -1; - ConnectionBase(string h, int p): host(h), port(p), source(AF_INET) {} + ConnectionBase(std::string h, int p): host(h), port(p), source(AF_INET) {} }; struct Connection: ConnectionBase @@ -76,7 +74,7 @@ class SrtCommon int error = SRT_SUCCESS; int reason = SRT_REJ_UNKNOWN; - Connection(string h, int p): ConnectionBase(h, p) {} + Connection(std::string h, int p): ConnectionBase(h, p) {} Connection(Connection&& old): ConnectionBase(old) { #if ENABLE_BONDING @@ -101,14 +99,14 @@ class SrtCommon int m_timeout = 0; //< enforces using SRTO_SNDTIMEO or SRTO_RCVTIMEO, depending on @a m_direction bool m_tsbpdmode = true; int m_outgoing_port = 0; - string m_mode; - string m_adapter; - map m_options; // All other options, as provided in the URI - vector m_group_nodes; - string m_group_type; - string m_group_config; + std::string m_mode; + std::string m_adapter; + std::map m_options; // All other options, as provided in the URI + std::vector m_group_nodes; + std::string m_group_type; + std::string m_group_config; #if ENABLE_BONDING - vector m_group_data; + std::vector m_group_data; #ifdef SRT_OLD_APP_READER int32_t m_group_seqno = -1; @@ -117,7 +115,7 @@ class SrtCommon int32_t sequence; bytevector packet; }; - map m_group_positions; + std::map m_group_positions; SRTSOCKET m_group_active; // The link from which the last packet was delivered #endif #endif @@ -131,8 +129,8 @@ class SrtCommon void UpdateGroupStatus(const SRT_SOCKGROUPDATA* grpdata, size_t grpdata_size); public: - void InitParameters(string host, string path, map par); - void PrepareListener(string host, int port, int backlog); + void InitParameters(std::string host, std::string path, std::map par); + void PrepareListener(std::string host, int port, int backlog); void StealFrom(SrtCommon& src); void AcceptNewClient(); @@ -150,22 +148,22 @@ class SrtCommon protected: - void Error(string src, int reason = SRT_REJ_UNKNOWN, int force_result = 0); - void Init(string host, int port, string path, map par, SRT_EPOLL_OPT dir); + void Error(std::string src, int reason = SRT_REJ_UNKNOWN, int force_result = 0); + void Init(std::string host, int port, std::string path, std::map par, SRT_EPOLL_OPT dir); int AddPoller(SRTSOCKET socket, int modes); virtual int ConfigurePost(SRTSOCKET sock); virtual int ConfigurePre(SRTSOCKET sock); - void OpenClient(string host, int port); + void OpenClient(std::string host, int port); #if ENABLE_BONDING void OpenGroupClient(); #endif void PrepareClient(); void SetupAdapter(const std::string& host, int port); - void ConnectClient(string host, int port); - void SetupRendezvous(string adapter, string host, int port); + void ConnectClient(std::string host, int port); + void SetupRendezvous(std::string adapter, std::string host, int port); - void OpenServer(string host, int port, int backlog = 1) + void OpenServer(std::string host, int port, int backlog = 1) { PrepareListener(host, port, backlog); if (transmit_accept_hook_fn) @@ -175,7 +173,7 @@ class SrtCommon AcceptNewClient(); } - void OpenRendezvous(string adapter, string host, int port) + void OpenRendezvous(std::string adapter, std::string host, int port) { PrepareClient(); SetupRendezvous(adapter, host, port); @@ -284,11 +282,11 @@ class SrtModel: public SrtCommon public: bool is_caller = false; bool is_rend = false; - string m_host; + std::string m_host; int m_port = 0; - SrtModel(string host, int port, map par); + SrtModel(std::string host, int port, std::map par); void Establish(std::string& w_name); void Close() @@ -320,7 +318,7 @@ class UdpSource: public virtual Source, public virtual UdpCommon bool eof = true; public: - UdpSource(string host, int port, const map& attr); + UdpSource(std::string host, int port, const std::map& attr); MediaPacket Read(size_t chunk) override; @@ -331,7 +329,7 @@ class UdpSource: public virtual Source, public virtual UdpCommon class UdpTarget: public virtual Target, public virtual UdpCommon { public: - UdpTarget(string host, int port, const map& attr); + UdpTarget(std::string host, int port, const std::map& attr); void Write(const MediaPacket& data) override; bool IsOpen() override { return m_sock != -1; } @@ -341,7 +339,7 @@ class UdpTarget: public virtual Target, public virtual UdpCommon class UdpRelay: public Relay, public UdpSource, public UdpTarget { public: - UdpRelay(string host, int port, const map& attr): + UdpRelay(std::string host, int port, const std::map& attr): UdpSource(host, port, attr), UdpTarget(host, port, attr) {