diff --git a/.github/workflows/cxx11-macos.yaml b/.github/workflows/cxx11-macos.yaml index 0aa9d420c..e3e6b1f8a 100644 --- a/.github/workflows/cxx11-macos.yaml +++ b/.github/workflows/cxx11-macos.yaml @@ -18,7 +18,7 @@ jobs: - name: configure run: | mkdir _build && cd _build - cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DUSE_CXX_STD=14 + cmake ../ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DUSE_CXX_STD=14 - name: build run: cd _build && cmake --build ./ - name: test diff --git a/.github/workflows/cxx11-ubuntu.yaml b/.github/workflows/cxx11-ubuntu.yaml index aa74e1fce..918bbcd22 100644 --- a/.github/workflows/cxx11-ubuntu.yaml +++ b/.github/workflows/cxx11-ubuntu.yaml @@ -19,7 +19,7 @@ jobs: - name: configure run: | mkdir _build && cd _build - cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=ON -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DENABLE_TESTING=ON -DENABLE_EXAMPLES=ON -DENABLE_CODE_COVERAGE=ON + cmake ../ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=ON -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DENABLE_TESTING=ON -DENABLE_EXAMPLES=ON -DENABLE_CODE_COVERAGE=ON - name: build run: cd _build && build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build . - name: test diff --git a/.github/workflows/cxx11-win.yaml b/.github/workflows/cxx11-win.yaml index 1a9e10a95..f1554053d 100644 --- a/.github/workflows/cxx11-win.yaml +++ b/.github/workflows/cxx11-win.yaml @@ -17,8 +17,8 @@ jobs: - name: configure run: | md _build && cd _build - cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON + cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DUSE_CXX_STD=c++11 - name: build - run: cd _build && cmake --build ./ --config Release + run: cd _build && cmake --build ./ --config Release --verbose - name: test run: cd _build && ctest -E "TestIPv6.v6_calls_v4|TestConnectionTimeout.BlockingLoop" --extra-verbose -C Release diff --git a/apps/apputil.hpp b/apps/apputil.hpp index acb28d076..1a0b158e0 100644 --- a/apps/apputil.hpp +++ b/apps/apputil.hpp @@ -20,6 +20,7 @@ #include "netinet_any.h" #include "utilities.h" +#include "srt.h" #if _WIN32 @@ -336,4 +337,60 @@ std::string OptionHelpItem(const OptionName& o); const char* SRTClockTypeStr(); void PrintLibVersion(); + +namespace srt +{ + +struct OptionSetterProxy +{ + SRTSOCKET s; + int result = -1; + + OptionSetterProxy(SRTSOCKET ss): s(ss) {} + + struct OptionProxy + { + OptionSetterProxy& parent; + SRT_SOCKOPT opt; + +#define SPEC(type) \ + OptionProxy& operator=(const type& val)\ + {\ + parent.result = srt_setsockflag(parent.s, opt, &val, sizeof val);\ + return *this;\ + } + + SPEC(int32_t); + SPEC(int64_t); + SPEC(bool); +#undef SPEC + + template + OptionProxy& operator=(const char (&val)[N]) + { + parent.result = srt_setsockflag(parent.s, opt, val, N-1); + return *this; + } + + OptionProxy& operator=(const std::string& val) + { + parent.result = srt_setsockflag(parent.s, opt, val.c_str(), val.size()); + return *this; + } + }; + + OptionProxy operator[](SRT_SOCKOPT opt) + { + return OptionProxy {*this, opt}; + } + + operator int() { return result; } +}; + +inline OptionSetterProxy setopt(SRTSOCKET socket) +{ + return OptionSetterProxy(socket); +} + +} #endif // INC_SRT_APPCOMMON_H diff --git a/configure-data.tcl b/configure-data.tcl index 0496f52cd..3510a9645 100644 --- a/configure-data.tcl +++ b/configure-data.tcl @@ -191,7 +191,55 @@ proc preprocess {} { } } -proc GetCompilerCommand {} { +# Added also the Intel compiler names, just in case. +set compiler_map { + cc c++ + gcc g++ + icc icpc + icx icpx +} + +proc SplitCompilerVersionSuffix {cmd} { + # If there's no version suffix, return just $cmd. + # Otherwise return a list with cmd cut and version suffix + + set parts [split $cmd -] + if {[llength $parts] == 1} { + return $cmd + } + + set last [lindex $parts end] + if {![regexp {[0-9]+.*} $last]} { + return $cmd + } + + # Got the version + if {[llength $parts] == 2} { + set first [lindex $parts 0] + } else { + set first [join [lrange $parts 0 end-1] -] + } + + return [list $first -$last] +} + +# This uses 'compiler' in the form of the C compiler +# command line. For C++ it returns the C++ command line, +# which is normally the C compiler command with ++. +proc GetCompilerCmdName {compiler lang} { + lassign [SplitCompilerVersionSuffix $compiler] compiler suffix + if {$lang == "c++"} { + if { [dict exists $::compiler_map $compiler] } { + return [dict get $::compiler_map $compiler]$suffix + } + + return ${compiler}++${suffix} + } + + return $compiler${suffix} +} + +proc GetCompilerCommand { {lang {}} } { # Expect that the compiler was set through: # --with-compiler-prefix # --cmake-c[++]-compiler @@ -204,21 +252,25 @@ proc GetCompilerCommand {} { if { [info exists ::optval(--with-compiler-prefix)] } { set prefix $::optval(--with-compiler-prefix) - return ${prefix}$compiler + return ${prefix}[GetCompilerCmdName $compiler $lang] } else { - return $compiler + return [GetCompilerCmdName $compiler $lang] } - if { [info exists ::optval(--cmake-c-compiler)] } { - return $::optval(--cmake-c-compiler) + if { $lang != "c++" } { + if { [info exists ::optval(--cmake-c-compiler)] } { + return $::optval(--cmake-c-compiler) + } } - if { [info exists ::optval(--cmake-c++-compiler)] } { - return $::optval(--cmake-c++-compiler) - } + if { $lang != "c" } { + if { [info exists ::optval(--cmake-c++-compiler)] } { + return $::optval(--cmake-c++-compiler) + } - if { [info exists ::optval(--cmake-cxx-compiler)] } { - return $::optval(--cmake-cxx-compiler) + if { [info exists ::optval(--cmake-cxx-compiler)] } { + return $::optval(--cmake-cxx-compiler) + } } puts "NOTE: Cannot obtain compiler, assuming toolchain file will do what's necessary" @@ -284,6 +336,18 @@ proc postprocess {} { } else { puts "CONFIGURE: default compiler used" } + + # Complete the variables before calling cmake, otherwise it might not work + + if { [info exists ::optval(--with-compiler-type)] } { + if { ![info exists ::optval(--cmake-c-compiler)] } { + lappend ::cmakeopt "-DCMAKE_C_COMPILER=[GetCompilerCommand c]" + } + + if { ![info exists ::optval(--cmake-c++-compiler)] } { + lappend ::cmakeopt "-DCMAKE_CXX_COMPILER=[GetCompilerCommand c++]" + } + } } if { $::srt_name != "" } { diff --git a/srtcore/api.h b/srtcore/api.h index b5d6be915..48e7827f8 100644 --- a/srtcore/api.h +++ b/srtcore/api.h @@ -486,7 +486,11 @@ class CUDTUnited bool acquire(CUDTUnited& glob, CUDTSocket* s) { if (s == NULL) + { + socket = NULL; return false; + } + const bool caught = glob.acquireSocket(s); socket = caught ? s : NULL; return caught; diff --git a/srtcore/common.cpp b/srtcore/common.cpp index 6d747ecaa..d3fd4f22c 100644 --- a/srtcore/common.cpp +++ b/srtcore/common.cpp @@ -461,6 +461,54 @@ bool SrtParseConfig(const string& s, SrtConfig& w_config) return true; } + +std::string FormatLossArray(const std::vector< std::pair >& lra) +{ + std::ostringstream os; + + os << "[ "; + for (std::vector< std::pair >::const_iterator i = lra.begin(); i != lra.end(); ++i) + { + int len = CSeqNo::seqoff(i->first, i->second); + os << "%" << i->first; + if (len > 1) + os << "+" << len; + os << " "; + } + + os << "]"; + return os.str(); +} + +ostream& PrintEpollEvent(ostream& os, int events, int et_events) +{ + static pair const namemap [] = { + make_pair(SRT_EPOLL_IN, "R"), + make_pair(SRT_EPOLL_OUT, "W"), + make_pair(SRT_EPOLL_ERR, "E"), + make_pair(SRT_EPOLL_UPDATE, "U") + }; + bool any = false; + + const int N = (int)Size(namemap); + + for (int i = 0; i < N; ++i) + { + if (events & namemap[i].first) + { + os << "["; + if (et_events & namemap[i].first) + os << "^"; + os << namemap[i].second << "]"; + any = true; + } + } + + if (!any) + os << "[]"; + + return os; +} } // namespace srt namespace srt_logging diff --git a/srtcore/common.h b/srtcore/common.h index 6a8912118..ff84c3faf 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -1435,23 +1435,8 @@ inline bool checkMappedIPv4(const sockaddr_in6& sa) return checkMappedIPv4(addr); } -inline std::string FormatLossArray(const std::vector< std::pair >& lra) -{ - std::ostringstream os; - - os << "[ "; - for (std::vector< std::pair >::const_iterator i = lra.begin(); i != lra.end(); ++i) - { - int len = CSeqNo::seqoff(i->first, i->second); - os << "%" << i->first; - if (len > 1) - os << "+" << len; - os << " "; - } - - os << "]"; - return os.str(); -} +std::string FormatLossArray(const std::vector< std::pair >& lra); +std::ostream& PrintEpollEvent(std::ostream& os, int events, int et_events = 0); } // namespace srt diff --git a/srtcore/congctl.cpp b/srtcore/congctl.cpp index b9265c046..85d4cda97 100644 --- a/srtcore/congctl.cpp +++ b/srtcore/congctl.cpp @@ -595,7 +595,7 @@ class FileCC : public SrtCongestionControlBase { m_dPktSndPeriod = m_dCWndSize / (m_parent->SRTT() + m_iRCInterval); HLOGC(cclog.Debug, log << "FileCC: CHKTIMER, SLOWSTART:OFF, sndperiod=" << m_dPktSndPeriod << "us AS wndsize/(RTT+RCIV) (wndsize=" - << setprecision(6) << m_dCWndSize << " RTT=" << m_parent->SRTT() << " RCIV=" << m_iRCInterval << ")"); + << m_dCWndSize << " RTT=" << m_parent->SRTT() << " RCIV=" << m_iRCInterval << ")"); } } else diff --git a/srtcore/epoll.cpp b/srtcore/epoll.cpp index e2b861bf9..8cd8440c7 100644 --- a/srtcore/epoll.cpp +++ b/srtcore/epoll.cpp @@ -71,12 +71,6 @@ modified by using namespace std; using namespace srt::sync; -#if ENABLE_HEAVY_LOGGING -namespace srt { -static ostream& PrintEpollEvent(ostream& os, int events, int et_events = 0); -} -#endif - namespace srt_logging { extern Logger eilog, ealog; @@ -956,31 +950,6 @@ int srt::CEPoll::update_events(const SRTSOCKET& uid, std::set& eids, const namespace srt { -static ostream& PrintEpollEvent(ostream& os, int events, int et_events) -{ - static pair const namemap [] = { - make_pair(SRT_EPOLL_IN, "R"), - make_pair(SRT_EPOLL_OUT, "W"), - make_pair(SRT_EPOLL_ERR, "E"), - make_pair(SRT_EPOLL_UPDATE, "U") - }; - - const int N = (int)Size(namemap); - - for (int i = 0; i < N; ++i) - { - if (events & namemap[i].first) - { - os << "["; - if (et_events & namemap[i].first) - os << "^"; - os << namemap[i].second << "]"; - } - } - - return os; -} - string DisplayEpollResults(const std::map& sockset) { typedef map fmap_t; diff --git a/srtcore/handshake.cpp b/srtcore/handshake.cpp index f8f03c84d..c97b4e2a3 100644 --- a/srtcore/handshake.cpp +++ b/srtcore/handshake.cpp @@ -300,7 +300,7 @@ std::string srt::SrtFlagString(int32_t flags) #define LEN(arr) (sizeof (arr)/(sizeof ((arr)[0]))) std::string output; - static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI" }; + static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI", "FilterCapable" }; size_t i = 0; for (; i < LEN(namera); ++i) diff --git a/srtcore/logging.cpp b/srtcore/logging.cpp index d309b1b8a..cc9d14e1d 100644 --- a/srtcore/logging.cpp +++ b/srtcore/logging.cpp @@ -80,7 +80,7 @@ void LogDispatcher::SendLogLine(const char* file, int line, const std::string& a } else if ( src_config->log_stream ) { - (*src_config->log_stream) << msg; + src_config->log_stream->write(msg.data(), msg.size()); src_config->log_stream->flush(); } src_config->unlock(); diff --git a/srtcore/logging.h b/srtcore/logging.h index 37eb31b46..4f6a76005 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -56,7 +56,7 @@ written by { \ srt_logging::LogDispatcher::Proxy log(logdes); \ log.setloc(__FILE__, __LINE__, __FUNCTION__); \ - const srt_logging::LogDispatcher::Proxy& log_prox SRT_ATR_UNUSED = args; \ + { (void)(const srt_logging::LogDispatcher::Proxy&)(args); } \ } // LOGF uses printf-like style formatting. @@ -154,6 +154,7 @@ struct SRT_API LogDispatcher LogLevel::type level; static const size_t MAX_PREFIX_SIZE = 32; char prefix[MAX_PREFIX_SIZE+1]; + size_t prefix_len; srt::sync::atomic enabled; LogConfig* src_config; @@ -168,30 +169,30 @@ struct SRT_API LogDispatcher enabled(false), src_config(&config) { - // XXX stpcpy desired, but not enough portable - // Composing the exact prefix is not critical, so simply - // cut the prefix, if the length is exceeded - - // See Logger::Logger; we know this has normally 2 characters, - // except !!FATAL!!, which has 9. Still less than 32. - // If the size of the FA name together with severity exceeds the size, - // just skip the former. - if (logger_pfx && strlen(prefix) + strlen(logger_pfx) + 1 < MAX_PREFIX_SIZE) + const size_t your_pfx_len = your_pfx ? strlen(your_pfx) : 0; + const size_t logger_pfx_len = logger_pfx ? strlen(logger_pfx) : 0; + + if (logger_pfx && your_pfx_len + logger_pfx_len + 1 < MAX_PREFIX_SIZE) { -#if defined(_MSC_VER) && _MSC_VER < 1900 - _snprintf(prefix, MAX_PREFIX_SIZE, "%s:%s", your_pfx, logger_pfx); -#else - snprintf(prefix, MAX_PREFIX_SIZE + 1, "%s:%s", your_pfx, logger_pfx); -#endif + memcpy(prefix, your_pfx, your_pfx_len); + prefix[your_pfx_len] = ':'; + memcpy(prefix + your_pfx_len + 1, logger_pfx, logger_pfx_len); + prefix[your_pfx_len + logger_pfx_len + 1] = '\0'; + prefix_len = your_pfx_len + logger_pfx_len + 1; + } + else if (your_pfx) + { + // Prefix too long, so copy only your_pfx and only + // as much as it fits + size_t copylen = std::min(+MAX_PREFIX_SIZE, your_pfx_len); + memcpy(prefix, your_pfx, copylen); + prefix[copylen] = '\0'; + prefix_len = copylen; } else { -#ifdef _MSC_VER - strncpy_s(prefix, MAX_PREFIX_SIZE + 1, your_pfx, _TRUNCATE); -#else - strncpy(prefix, your_pfx, MAX_PREFIX_SIZE); - prefix[MAX_PREFIX_SIZE] = '\0'; -#endif + prefix[0] = '\0'; + prefix_len = 0; } config.subscribe(this); Update(); @@ -352,9 +353,9 @@ struct LogDispatcher::Proxy ~Proxy() { - if ( that_enabled ) + if (that_enabled) { - if ( (flags & SRT_LOGF_DISABLE_EOL) == 0 ) + if ((flags & SRT_LOGF_DISABLE_EOL) == 0) os << std::endl; that.SendLogLine(i_file, i_line, area, os.str()); } @@ -395,7 +396,7 @@ struct LogDispatcher::Proxy buf[len-1] = '\0'; } - os << buf; + os.write(buf, len); return *this; } }; diff --git a/srtcore/queue.h b/srtcore/queue.h index 132b670b3..48bedd9af 100644 --- a/srtcore/queue.h +++ b/srtcore/queue.h @@ -591,6 +591,10 @@ struct CMultiplexer , m_pRcvQueue(NULL) , m_pChannel(NULL) , m_pTimer(NULL) + , m_iPort(0) + , m_iIPversion(0) + , m_iRefCount(1) + , m_iID(-1) { } diff --git a/srtcore/threadname.h b/srtcore/threadname.h index 1c064c86c..6233e36fc 100644 --- a/srtcore/threadname.h +++ b/srtcore/threadname.h @@ -103,6 +103,8 @@ class ThreadName #elif defined(HAVE_PTHREAD_SETNAME_NP) #if defined(__APPLE__) return pthread_setname_np(name) == 0; + #elif defined(__NetBSD__) + return pthread_setname_np(pthread_self(), "%s", name) == 0; #else return pthread_setname_np(pthread_self(), name) == 0; #endif diff --git a/srtcore/utilities.h b/srtcore/utilities.h index 1786cf0ae..ca8c365a3 100644 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -981,30 +981,13 @@ inline std::string FormatBinaryString(const uint8_t* bytes, size_t size) if ( size == 0 ) return ""; - //char buf[256]; using namespace std; ostringstream os; + os << setfill('0') << setw(2) << hex << uppercase; - // I know, it's funny to use sprintf and ostringstream simultaneously, - // but " %02X" in iostream is: << " " << hex << uppercase << setw(2) << setfill('0') << VALUE << setw(1) - // Too noisy. OTOH ostringstream solves the problem of memory allocation - // for a string of unpredictable size. - //sprintf(buf, "%02X", int(bytes[0])); - - os.fill('0'); - os.width(2); - os.setf(ios::basefield, ios::hex); - os.setf(ios::uppercase); - - //os << buf; - os << int(bytes[0]); - - - for (size_t i = 1; i < size; ++i) + for (size_t i = 0; i < size; ++i) { - //sprintf(buf, " %02X", int(bytes[i])); - //os << buf; os << int(bytes[i]); } return os.str(); diff --git a/test/test_bonding.cpp b/test/test_bonding.cpp index f40a52eb5..0e48c8a04 100644 --- a/test/test_bonding.cpp +++ b/test/test_bonding.cpp @@ -484,3 +484,83 @@ TEST(Bonding, Options) srt_close(grp); } +inline SRT_SOCKGROUPCONFIG PrepareEndpoint(const std::string& host, int port) +{ + srt::sockaddr_any sa = srt::CreateAddr(host, port, AF_INET); + return srt_prepare_endpoint(NULL, sa.get(), sa.size()); +} + +// This test will create a listener and then the group that should +// connect members, where the first one fail, and two next should +// succeed. Then sends a single packet over that link and makes sure +// it's properly received, then the second packet isn't read. +TEST(Bonding, InitialFailure) +{ + using namespace std; + using namespace srt; + + TestInit srtinit; + MAKE_UNIQUE_SOCK(lsn, "Listener", srt_create_socket()); + MAKE_UNIQUE_SOCK(grp, "GrpCaller", srt_create_group(SRT_GTYPE_BROADCAST)); + + // Create the listener on port 5555. + int allow = 1; + ASSERT_NE(srt_setsockflag(lsn, SRTO_GROUPCONNECT, &allow, sizeof allow), SRT_ERROR); + + sockaddr_any sa = CreateAddr("127.0.0.1", 5555, AF_INET); + ASSERT_NE(srt_bind(lsn, sa.get(), sa.size()), SRT_ERROR); + ASSERT_NE(srt_listen(lsn, 5), SRT_ERROR); + + // Create a group + // Connect 3 members in the group. + std::vector targets; + targets.push_back(PrepareEndpoint("127.0.0.1", 5556)); // NOTE: NONEXISTENT LISTENER + targets.push_back(PrepareEndpoint("127.0.0.1", 5555)); + targets.push_back(PrepareEndpoint("127.0.0.1", 5555)); + + // This should block until the connection is established, but + // accepted socket should be spawned and just wait for extraction. + const SRTSOCKET conn = srt_connect_group(grp, targets.data(), (int)targets.size()); + EXPECT_NE(conn, SRT_INVALID_SOCK); + + // Now check if the accept is ready + sockaddr_any revsa; + const SRTSOCKET gs = srt_accept(lsn, revsa.get(), &revsa.len); + EXPECT_NE(gs, SRT_INVALID_SOCK); + + // Make sure that it was the group accepted + EXPECT_EQ(gs & SRTGROUP_MASK, SRTGROUP_MASK); + + // Set 1s reading timeout on the socket so that reading won't wait forever, + // as it should fail at the second reading. + int read_timeout = 500; // 0.5s + EXPECT_NE(srt_setsockflag(gs, SRTO_RCVTIMEO, &read_timeout, sizeof (read_timeout)), SRT_ERROR); + + int lsn_isn = -1, lsn_isn_size = sizeof (int); + EXPECT_NE(srt_getsockflag(gs, SRTO_ISN, &lsn_isn, &lsn_isn_size), SRT_ERROR); + + // Now send a packet + + string packet_data = "PREDEFINED PACKET DATA"; + EXPECT_NE(srt_send(grp, packet_data.data(), packet_data.size()), SRT_ERROR); + + char outbuf[1316]; + SRT_MSGCTRL mc = srt_msgctrl_default; + int recvlen = srt_recvmsg2(gs, outbuf, 1316, &mc); + EXPECT_EQ(recvlen, int(packet_data.size())); + + if (recvlen > 0) + { + outbuf[recvlen] = 0; + EXPECT_EQ(outbuf, packet_data); + } + EXPECT_EQ(mc.pktseq, lsn_isn); + + recvlen = srt_recv(gs, outbuf, 80); + EXPECT_EQ(recvlen, int(SRT_ERROR)); + + srt_close(gs); + srt_close(grp); + srt_close(lsn); +} + diff --git a/test/test_env.h b/test/test_env.h index e20905351..b425fa808 100644 --- a/test/test_env.h +++ b/test/test_env.h @@ -53,7 +53,11 @@ class TestInit static void start(int& w_retstatus); static void stop(); - TestInit() { start((ninst)); } + TestInit() + { + start((ninst)); + HandlePerTestOptions(); + } ~TestInit() { stop(); } void HandlePerTestOptions(); @@ -115,7 +119,6 @@ class Test: public testing::Test void SetUp() override final { init_holder.reset(new TestInit); - init_holder->HandlePerTestOptions(); setup(); } diff --git a/testing/srt-test-live.cpp b/testing/srt-test-live.cpp index 1811220c8..12478e461 100644 --- a/testing/srt-test-live.cpp +++ b/testing/srt-test-live.cpp @@ -301,7 +301,7 @@ extern "C" int SrtCheckGroupHook(void* , SRTSOCKET acpsock, int , const sockaddr size = sizeof gt; if (-1 != srt_getsockflag(acpsock, SRTO_GROUPTYPE, >, &size)) { - if (gt < Size(gtypes)) + if (size_t(gt) < Size(gtypes)) Verb(" type=", gtypes[gt], VerbNoEOL); else Verb(" type=", int(gt), VerbNoEOL); diff --git a/testing/srt-test-mpbond.cpp b/testing/srt-test-mpbond.cpp index 60d91df2c..157fa9728 100644 --- a/testing/srt-test-mpbond.cpp +++ b/testing/srt-test-mpbond.cpp @@ -189,10 +189,7 @@ int main( int argc, char** argv ) SRTSOCKET s = srt_create_socket(); - //SRT_GROUPCONNTYPE gcon = SRTGC_GROUPONLY; - int gcon = 1; - srt_setsockflag(s, SRTO_GROUPCONNECT, &gcon, sizeof gcon); - + srt::setopt(s)[SRTO_GROUPCONNECT] = 1; srt_bind(s, sa.get(), sizeof sa); srt_listen(s, 5); diff --git a/testing/srt-test-multiplex.cpp b/testing/srt-test-multiplex.cpp index deb36554c..857557a5c 100644 --- a/testing/srt-test-multiplex.cpp +++ b/testing/srt-test-multiplex.cpp @@ -76,7 +76,7 @@ struct MediumPair bytevector initial_portion; string name; - MediumPair(unique_ptr s, unique_ptr t): src(move(s)), tar(move(t)) {} + MediumPair(unique_ptr s, unique_ptr t): src(std::move(s)), tar(std::move(t)) {} void Stop() { @@ -190,9 +190,9 @@ class MediaBase /// are still meant to be delivered to @c tar MediumPair& Link(std::unique_ptr src, std::unique_ptr tar, bytevector&& initial_portion, string name, string thread_name) { - media.emplace_back(move(src), move(tar)); + media.emplace_back(std::move(src), std::move(tar)); MediumPair& med = media.back(); - med.initial_portion = move(initial_portion); + med.initial_portion = std::move(initial_portion); med.name = name; // Ok, got this, so we can start transmission. @@ -382,7 +382,7 @@ bool SelectAndLink(SrtModel& m, string id, bool mode_output, string& w_msg) } bytevector dummy_initial_portion; - g_media_base.Link(move(source), move(target), move(dummy_initial_portion), os.str(), thread_name); + g_media_base.Link(std::move(source), std::move(target), std::move(dummy_initial_portion), os.str(), thread_name); return true; } diff --git a/testing/srt-test-relay.cpp b/testing/srt-test-relay.cpp index e7e5ae574..912af555e 100755 --- a/testing/srt-test-relay.cpp +++ b/testing/srt-test-relay.cpp @@ -320,7 +320,7 @@ SrtMainLoop::SrtMainLoop(const string& srt_uri, bool input_echoback, const strin Verb() << "Setting up output: " << spec; unique_ptr m { new TargetMedium }; m->Setup(Target::Create(spec)); - m_output_media.push_back(move(m)); + m_output_media.push_back(std::move(m)); } @@ -369,7 +369,7 @@ SrtMainLoop::SrtMainLoop(const string& srt_uri, bool input_echoback, const strin // Add SRT medium to output targets, and keep input medium empty. unique_ptr med { new TargetMedium }; med->Setup(m_srt_relay.get()); - m_output_media.push_back(move(med)); + m_output_media.push_back(std::move(med)); } else { diff --git a/testing/testactivemedia.cpp b/testing/testactivemedia.cpp index 96344f0b2..dd0393ea6 100644 --- a/testing/testactivemedia.cpp +++ b/testing/testactivemedia.cpp @@ -120,4 +120,20 @@ void TargetMedium::Runner() } } +bool TargetMedium::Schedule(const MediaPacket& data) +{ + LOGP(applog.Debug, "TargetMedium::Schedule 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) + { + LOGP(applog.Debug, "TargetMedium::Schedule: not running, discarding packet"); + return false; + } + + LOGP(applog.Debug, "TargetMedium(", typeid(*med).name(), "): Schedule: [", data.payload.size(), "] CLIENT -> BUFFER"); + buffer.push_back(data); + ready.notify_one(); + return true; +} diff --git a/testing/testactivemedia.hpp b/testing/testactivemedia.hpp index 011dcbfe7..e92abbe0c 100644 --- a/testing/testactivemedia.hpp +++ b/testing/testactivemedia.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "testmedia.hpp" @@ -29,7 +28,7 @@ struct Medium std::mutex buffer_lock; std::thread thr; std::condition_variable ready; - std::atomic running = {false}; + srt::sync::atomic running {false}; std::exception_ptr xp; // To catch exception thrown by a thread virtual void Runner() = 0; @@ -147,22 +146,7 @@ struct TargetMedium: Medium { void Runner() override; - bool Schedule(const MediaPacket& data) - { - LOGP(applog.Debug, "TargetMedium::Schedule 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) - { - LOGP(applog.Debug, "TargetMedium::Schedule: not running, discarding packet"); - return false; - } - - LOGP(applog.Debug, "TargetMedium(", typeid(*med).name(), "): Schedule: [", data.payload.size(), "] CLIENT -> BUFFER"); - buffer.push_back(data); - ready.notify_one(); - return true; - } + bool Schedule(const MediaPacket& data); void Clear() { diff --git a/testing/testmedia.cpp b/testing/testmedia.cpp index b9d8a0413..a7eb0541c 100755 --- a/testing/testmedia.cpp +++ b/testing/testmedia.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #if !defined(_WIN32) #include @@ -50,8 +49,8 @@ using srt_logging::SockStatusStr; using srt_logging::MemberStatusStr; #endif -std::atomic transmit_throw_on_interrupt {false}; -std::atomic transmit_int_state {false}; +srt::sync::atomic transmit_throw_on_interrupt {false}; +srt::sync::atomic transmit_int_state {false}; int transmit_bw_report = 0; unsigned transmit_stats_report = 0; size_t transmit_chunk_size = SRT_LIVE_DEF_PLSIZE; @@ -348,7 +347,7 @@ void SrtCommon::InitParameters(string host, string path, map par) } cc.token = token++; - m_group_nodes.push_back(move(cc)); + m_group_nodes.push_back(std::move(cc)); } par.erase("type"); @@ -3042,7 +3041,7 @@ extern unique_ptr CreateMedium(const string& uri) } if (ptr) - ptr->uri = move(u); + ptr->uri = std::move(u); return ptr; } diff --git a/testing/testmedia.hpp b/testing/testmedia.hpp index be72471d1..470e825ef 100644 --- a/testing/testmedia.hpp +++ b/testing/testmedia.hpp @@ -15,7 +15,8 @@ #include #include #include -#include + +#include // use srt::sync::atomic instead of std::atomic for the sake of logging #include "apputil.hpp" #include "statswriter.hpp" @@ -25,7 +26,7 @@ extern srt_listen_callback_fn* transmit_accept_hook_fn; extern void* transmit_accept_hook_op; -extern std::atomic transmit_int_state; +extern srt::sync::atomic transmit_int_state; extern std::shared_ptr transmit_stats_writer; diff --git a/testing/testmediabase.hpp b/testing/testmediabase.hpp index 04a85d435..686198787 100644 --- a/testing/testmediabase.hpp +++ b/testing/testmediabase.hpp @@ -11,17 +11,17 @@ #ifndef INC_SRT_COMMON_TRANMITBASE_HPP #define INC_SRT_COMMON_TRANMITBASE_HPP -#include #include #include #include #include #include +#include "sync.h" #include "uriparser.hpp" typedef std::vector bytevector; -extern std::atomic transmit_throw_on_interrupt; +extern srt::sync::atomic transmit_throw_on_interrupt; extern int transmit_bw_report; extern unsigned transmit_stats_report; extern size_t transmit_chunk_size;