Skip to content

Commit

Permalink
[core] Added length type wrapper in sockaddr_any for convenience. (#1492
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ethouris committed Sep 1, 2020
1 parent 614695e commit 6383693
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 1 addition & 3 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,11 @@ unique_ptr<Medium> SrtMedium::Accept()
unique_ptr<Medium> TcpMedium::Accept()
{
sockaddr_any sa;
socklen_t salen = sizeof sa;
int s = ::accept(m_socket, (sa.get()), (&salen));
int s = ::accept(m_socket, (sa.get()), (&sa.syslen()));
if (s == -1)
{
Error(errno, "accept");
}
sa.len = salen;

// Configure 1s timeout
timeval timeout_1s { 1, 0 };
Expand Down
23 changes: 23 additions & 0 deletions srtcore/netinet_any.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ struct sockaddr_any
// back here from the value of `syslen_t`.
len_t len;

struct SysLenWrapper
{
syslen_t syslen;
len_t& backwriter;
syslen_t* operator&() { return &syslen; }

SysLenWrapper(len_t& source): syslen(source), backwriter(source)
{
}

~SysLenWrapper()
{
backwriter = syslen;
}
};

// Usage:
// ::accept(lsn_sock, sa.get(), &sa.syslen());
SysLenWrapper syslen()
{
return SysLenWrapper(len);
}

static size_t storage_size()
{
typedef union
Expand Down
4 changes: 1 addition & 3 deletions testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2517,16 +2517,14 @@ class UdpSource: public virtual Source, public virtual UdpCommon
{
bytevector data(chunk);
sockaddr_any sa(sadr.family());
socklen_t si = sa.size();
int64_t srctime = 0;
int stat = recvfrom(m_sock, data.data(), (int) chunk, 0, sa.get(), &si);
int stat = recvfrom(m_sock, data.data(), (int) chunk, 0, sa.get(), &sa.syslen());
if (transmit_use_sourcetime)
{
srctime = srt_time_now();
}
if (stat == -1)
Error(SysError(), "UDP Read/recvfrom");
sa.len = si;

if (stat < 1)
{
Expand Down

0 comments on commit 6383693

Please sign in to comment.