Skip to content

Commit

Permalink
Updated and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Malecki committed Sep 9, 2024
2 parents f26a087 + ab000e3 commit 291c6c2
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cxx11-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 34 additions & 3 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,52 @@ proc preprocess {} {
}
}

# 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]
return [dict get $::compiler_map $compiler]$suffix
}

return ${compiler}++
return ${compiler}++${suffix}
}

return $compiler
return $compiler${suffix}
}

proc GetCompilerCommand { {lang {}} } {
Expand Down
2 changes: 1 addition & 1 deletion srtcore/congctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion srtcore/handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 26 additions & 25 deletions srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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.
Expand Down Expand Up @@ -147,6 +147,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;
LogConfig* src_config;

bool isset(int flg) { return (src_config->flags & flg) != 0; }
Expand All @@ -159,30 +160,30 @@ struct SRT_API LogDispatcher
level(log_level),
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;
}
}

Expand Down Expand Up @@ -338,9 +339,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());
}
Expand Down Expand Up @@ -381,7 +382,7 @@ struct LogDispatcher::Proxy
buf[len-1] = '\0';
}

os << buf;
os.write(buf, len);
return *this;
}
};
Expand Down Expand Up @@ -494,7 +495,7 @@ inline void LogDispatcher::SendLogLine(const char* file, int line, const std::st
}
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();
Expand Down
4 changes: 4 additions & 0 deletions srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
2 changes: 2 additions & 0 deletions srtcore/threadname.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 2 additions & 19 deletions srtcore/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
77 changes: 77 additions & 0 deletions test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,80 @@ 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<SRT_SOCKGROUPCONFIG> 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, packet_data.size());
outbuf[recvlen] = 0;

EXPECT_EQ(outbuf, packet_data);
EXPECT_EQ(mc.pktseq, lsn_isn);

recvlen = srt_recv(gs, outbuf, 80);
EXPECT_EQ(recvlen, SRT_ERROR);

srt_close(gs);
srt_close(grp);
srt_close(lsn);
}

1 change: 0 additions & 1 deletion test/test_epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using namespace std;
using namespace srt;



TEST(CEPoll, InfiniteWait)
{
srt::TestInit srtinit;
Expand Down
5 changes: 1 addition & 4 deletions testing/srt-test-mpbond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions testing/srt-test-multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct MediumPair
bytevector initial_portion;
string name;

MediumPair(unique_ptr<Source> s, unique_ptr<Target> t): src(move(s)), tar(move(t)) {}
MediumPair(unique_ptr<Source> s, unique_ptr<Target> t): src(std::move(s)), tar(std::move(t)) {}

void Stop()
{
Expand Down Expand Up @@ -190,9 +190,9 @@ class MediaBase
/// are still meant to be delivered to @c tar
MediumPair& Link(std::unique_ptr<Source> src, std::unique_ptr<Target> 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.
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions testing/srt-test-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ SrtMainLoop::SrtMainLoop(const string& srt_uri, bool input_echoback, const strin
Verb() << "Setting up output: " << spec;
unique_ptr<TargetMedium> m { new TargetMedium };
m->Setup(Target::Create(spec));
m_output_media.push_back(move(m));
m_output_media.push_back(std::move(m));
}


Expand Down Expand Up @@ -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<TargetMedium> 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
{
Expand Down
Loading

0 comments on commit 291c6c2

Please sign in to comment.