Skip to content

Commit

Permalink
[core] Moved sockaddr_any inside the srt namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed May 2, 2022
1 parent 909c8fb commit 9761063
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 48 deletions.
39 changes: 20 additions & 19 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions apps/apputil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& in, std::string sep);

template <class VarType, class ValType>
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ testmedia.cpp
*/

using namespace std;
using namespace srt;

const srt_logging::LogFA SRT_LOGFA_APP = 10;
namespace srt_logging
Expand Down
3 changes: 2 additions & 1 deletion apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions srtcore/netinet_any.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,4 +421,6 @@ inline sockaddr_any::TypeMap<AF_INET>::type& sockaddr_any::get<AF_INET>() { retu
template <>
inline sockaddr_any::TypeMap<AF_INET6>::type& sockaddr_any::get<AF_INET6>() { return sin6; }

} // namespace srt

#endif
2 changes: 1 addition & 1 deletion test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions test/test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/test_ipv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "srt.h"
#include "netinet_any.h"

using srt::sockaddr_any;

class TestIPv6
: public ::testing::Test
{
Expand Down
1 change: 1 addition & 0 deletions test/test_many_connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef int SOCKET;
#include "api.h"

using namespace std;
using srt::sockaddr_any;


class TestConnection
Expand Down
36 changes: 19 additions & 17 deletions test/test_reuseaddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion testing/srt-test-mpbond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void OnINT_SetIntState(int)
mpbond_int_state = true;
}


using namespace srt;


int main( int argc, char** argv )
Expand Down
1 change: 1 addition & 0 deletions testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "verbose.hpp"

using namespace std;
using namespace srt;

using srt_logging::KmStateStr;
using srt_logging::SockStatusStr;
Expand Down
6 changes: 3 additions & 3 deletions testing/testmedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -305,7 +305,7 @@ class UdpCommon
{
protected:
int m_sock = -1;
sockaddr_any sadr;
srt::sockaddr_any sadr;
std::string adapter;
std::map<std::string, std::string> m_options;
void Setup(std::string host, int port, std::map<std::string,std::string> attr);
Expand Down

0 comments on commit 9761063

Please sign in to comment.