diff --git a/apps/apputil.cpp b/apps/apputil.cpp index 68a9c4670..e5290408a 100644 --- a/apps/apputil.cpp +++ b/apps/apputil.cpp @@ -22,6 +22,7 @@ #include "srt_compat.h" using namespace std; +using namespace srt; // NOTE: MINGW currently does not include support for inet_pton(). See @@ -355,25 +356,25 @@ string OptionHelpItem(const OptionName& o) const char* SRTClockTypeStr() { - const int clock_type = srt_clock_type(); - - switch (clock_type) - { - case SRT_SYNC_CLOCK_STDCXX_STEADY: - return "CXX11_STEADY"; - case SRT_SYNC_CLOCK_GETTIME_MONOTONIC: - return "GETTIME_MONOTONIC"; - case SRT_SYNC_CLOCK_WINQPC: - return "WIN_QPC"; - case SRT_SYNC_CLOCK_MACH_ABSTIME: - return "MACH_ABSTIME"; - case SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY: - return "POSIX_GETTIMEOFDAY"; - default: - break; - } - - return "UNKNOWN VALUE"; + const int clock_type = srt_clock_type(); + + switch (clock_type) + { + case SRT_SYNC_CLOCK_STDCXX_STEADY: + return "CXX11_STEADY"; + case SRT_SYNC_CLOCK_GETTIME_MONOTONIC: + return "GETTIME_MONOTONIC"; + case SRT_SYNC_CLOCK_WINQPC: + return "WIN_QPC"; + case SRT_SYNC_CLOCK_MACH_ABSTIME: + return "MACH_ABSTIME"; + case SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY: + return "POSIX_GETTIMEOFDAY"; + default: + break; + } + + return "UNKNOWN VALUE"; } void PrintLibVersion() diff --git a/apps/apputil.hpp b/apps/apputil.hpp index 7737c05f7..acb28d076 100644 --- a/apps/apputil.hpp +++ b/apps/apputil.hpp @@ -85,7 +85,7 @@ inline int SysError() { return errno; } const int SysAGAIN = EAGAIN; #endif -sockaddr_any CreateAddr(const std::string& name, unsigned short port = 0, int pref_family = AF_UNSPEC); +srt::sockaddr_any CreateAddr(const std::string& name, unsigned short port = 0, int pref_family = AF_UNSPEC); std::string Join(const std::vector& in, std::string sep); template @@ -210,11 +210,11 @@ struct OptionScheme enum Args { ARG_NONE, ARG_ONE, ARG_VAR } type; OptionScheme(const OptionScheme&) = default; - OptionScheme(OptionScheme&& src) - : pid(src.pid) - , type(src.type) - { - } + OptionScheme(OptionScheme&& src) + : pid(src.pid) + , type(src.type) + { + } OptionScheme(const OptionName& id, Args tp); diff --git a/apps/srt-tunnel.cpp b/apps/srt-tunnel.cpp index b490cd9ee..d00c42f4c 100644 --- a/apps/srt-tunnel.cpp +++ b/apps/srt-tunnel.cpp @@ -59,6 +59,7 @@ testmedia.cpp */ using namespace std; +using namespace srt; const srt_logging::LogFA SRT_LOGFA_APP = 10; namespace srt_logging diff --git a/apps/transmitmedia.cpp b/apps/transmitmedia.cpp index da67bdaee..e90028bc6 100644 --- a/apps/transmitmedia.cpp +++ b/apps/transmitmedia.cpp @@ -38,6 +38,7 @@ #include "verbose.hpp" using namespace std; +using namespace srt; bool g_stats_are_printed_to_stdout = false; bool transmit_total_stats = false; @@ -401,7 +402,7 @@ void SrtCommon::ConnectClient(string host, int port) { sockaddr_any sa = CreateAddr(host, port); - sockaddr* psa = sa.get(); + sockaddr* psa = sa.get(); Verb() << "Connecting to " << host << ":" << port; diff --git a/srtcore/netinet_any.h b/srtcore/netinet_any.h index 3a17e228f..a38765c08 100644 --- a/srtcore/netinet_any.h +++ b/srtcore/netinet_any.h @@ -27,6 +27,9 @@ written by // You can use the instances of sockaddr_any in every place where sockaddr is // required. +namespace srt +{ + struct sockaddr_any { union @@ -418,4 +421,6 @@ inline sockaddr_any::TypeMap::type& sockaddr_any::get() { retu template <> inline sockaddr_any::TypeMap::type& sockaddr_any::get() { return sin6; } +} // namespace srt + #endif diff --git a/test/test_bonding.cpp b/test/test_bonding.cpp index 7d02ee5bb..b79ba2954 100644 --- a/test/test_bonding.cpp +++ b/test/test_bonding.cpp @@ -98,7 +98,7 @@ void listening_thread(bool should_read) ASSERT_GT(fds_len, 0); ASSERT_EQ(fds[0], server_sock); - sockaddr_any scl; + srt::sockaddr_any scl; int acp = srt_accept(server_sock, (scl.get()), (&scl.len)); ASSERT_NE(acp & SRTGROUP_MASK, 0); diff --git a/test/test_common.cpp b/test/test_common.cpp index 7a783ff12..901083dfa 100644 --- a/test/test_common.cpp +++ b/test/test_common.cpp @@ -5,6 +5,8 @@ #include "utilities.h" #include "common.h" +using namespace srt; + void test_cipaddress_pton(const char* peer_ip, int family, const uint32_t (&ip)[4]) { const int port = 4200; diff --git a/test/test_ipv6.cpp b/test/test_ipv6.cpp index 69a51bfbb..b7e2379bf 100644 --- a/test/test_ipv6.cpp +++ b/test/test_ipv6.cpp @@ -4,6 +4,8 @@ #include "srt.h" #include "netinet_any.h" +using srt::sockaddr_any; + class TestIPv6 : public ::testing::Test { diff --git a/test/test_many_connections.cpp b/test/test_many_connections.cpp index 759b6a461..0dbc62b4c 100644 --- a/test/test_many_connections.cpp +++ b/test/test_many_connections.cpp @@ -22,6 +22,7 @@ typedef int SOCKET; #include "api.h" using namespace std; +using srt::sockaddr_any; class TestConnection diff --git a/test/test_reuseaddr.cpp b/test/test_reuseaddr.cpp index 18ab5fdfa..4f9dfe726 100644 --- a/test/test_reuseaddr.cpp +++ b/test/test_reuseaddr.cpp @@ -8,6 +8,8 @@ #include "srt.h" #include "udt.h" +using srt::sockaddr_any; + // Copied from ../apps/apputil.cpp, can't really link this file here. sockaddr_any CreateAddr(const std::string& name, unsigned short port, int pref_family = AF_INET) { @@ -218,8 +220,8 @@ void serverSocket(std::string ip, int port, bool expect_success) int yes = 1; int no = 0; - SRTSOCKET m_bindsock = srt_create_socket(); - ASSERT_NE(m_bindsock, SRT_ERROR); + SRTSOCKET m_bindsock = srt_create_socket(); + ASSERT_NE(m_bindsock, SRT_ERROR); ASSERT_NE(srt_setsockopt(m_bindsock, 0, SRTO_RCVSYN, &no, sizeof no), SRT_ERROR); // for async connect ASSERT_NE(srt_setsockopt(m_bindsock, 0, SRTO_TSBPDMODE, &yes, sizeof yes), SRT_ERROR); @@ -251,33 +253,33 @@ void serverSocket(std::string ip, int port, bool expect_success) std::thread client(clientSocket, ip, port, expect_success); { // wait for connection from client - int rlen = 2; - SRTSOCKET read[2]; + int rlen = 2; + SRTSOCKET read[2]; - int wlen = 2; - SRTSOCKET write[2]; + int wlen = 2; + SRTSOCKET write[2]; ASSERT_NE(srt_epoll_wait(server_pollid, - read, &rlen, - write, &wlen, - 3000, // -1 is set for debuging purpose. - // in case of production we need to set appropriate value - 0, 0, 0, 0), SRT_ERROR ); + read, &rlen, + write, &wlen, + 3000, // -1 is set for debuging purpose. + // in case of production we need to set appropriate value + 0, 0, 0, 0), SRT_ERROR ); - ASSERT_EQ(rlen, 1); // get exactly one read event without writes - ASSERT_EQ(wlen, 0); // get exactly one read event without writes - ASSERT_EQ(read[0], m_bindsock); // read event is for bind socket + ASSERT_EQ(rlen, 1); // get exactly one read event without writes + ASSERT_EQ(wlen, 0); // get exactly one read event without writes + ASSERT_EQ(read[0], m_bindsock); // read event is for bind socket } sockaddr_any scl; - SRTSOCKET m_sock = srt_accept(m_bindsock, scl.get(), &scl.len); + SRTSOCKET m_sock = srt_accept(m_bindsock, scl.get(), &scl.len); if (m_sock == -1) { std::cout << "srt_accept: " << srt_getlasterror_str() << std::endl; } - ASSERT_NE(m_sock, SRT_INVALID_SOCK); + ASSERT_NE(m_sock, SRT_INVALID_SOCK); sockaddr_any showacp = (sockaddr*)&scl; std::cout << "Accepted from: " << showacp.str() << std::endl; @@ -308,7 +310,7 @@ void serverSocket(std::string ip, int port, bool expect_success) char pattern[4] = {1, 2, 3, 4}; ASSERT_EQ(srt_recvmsg(m_sock, buffer, sizeof buffer), - 1316); + 1316); EXPECT_EQ(memcmp(pattern, buffer, sizeof pattern), 0); diff --git a/testing/srt-test-mpbond.cpp b/testing/srt-test-mpbond.cpp index 3295d401a..c23b262b7 100644 --- a/testing/srt-test-mpbond.cpp +++ b/testing/srt-test-mpbond.cpp @@ -49,7 +49,7 @@ void OnINT_SetIntState(int) mpbond_int_state = true; } - +using namespace srt; int main( int argc, char** argv ) diff --git a/testing/testmedia.cpp b/testing/testmedia.cpp index 76ec20c04..64c0b66e9 100755 --- a/testing/testmedia.cpp +++ b/testing/testmedia.cpp @@ -42,6 +42,7 @@ #include "verbose.hpp" using namespace std; +using namespace srt; using srt_logging::KmStateStr; using srt_logging::SockStatusStr; diff --git a/testing/testmedia.hpp b/testing/testmedia.hpp index ec378080e..2dc8ceea3 100644 --- a/testing/testmedia.hpp +++ b/testing/testmedia.hpp @@ -61,8 +61,8 @@ class SrtCommon int port; int weight = 0; SRTSOCKET socket = SRT_INVALID_SOCK; - sockaddr_any source; - sockaddr_any target; + srt::sockaddr_any source; + srt::sockaddr_any target; int token = -1; ConnectionBase(string h, int p): host(h), port(p), source(AF_INET) {} @@ -305,7 +305,7 @@ class UdpCommon { protected: int m_sock = -1; - sockaddr_any sadr; + srt::sockaddr_any sadr; std::string adapter; std::map m_options; void Setup(std::string host, int port, std::map attr);