-
Notifications
You must be signed in to change notification settings - Fork 840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core][apps] Some refactoring per clang-reported warnings #3019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI builds need to be verbose, otherwise any error will be unclear. |
||
- name: test | ||
run: cd _build && ctest -E "TestIPv6.v6_calls_v4|TestConnectionTimeout.BlockingLoop" --extra-verbose -C Release |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 << ")"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Precision is 6 by default. |
||
} | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field wasn't added properly after adding a corresponding flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something for 1.5.4. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was considering it. All other changes don't disturb anyway. This one of course isn't a crash, at worst it will report this flag as "unknown". |
||
|
||
size_t i = 0; | ||
for (; i < LEN(namera); ++i) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); } \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Despite the unused attribute, this may generate a warning in some situations, depending on what is in |
||
} | ||
|
||
// LOGF uses printf-like style formatting. | ||
|
@@ -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; } | ||
|
@@ -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; | ||
} | ||
} | ||
|
||
|
@@ -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()); | ||
} | ||
|
@@ -381,7 +382,7 @@ struct LogDispatcher::Proxy | |
buf[len-1] = '\0'; | ||
} | ||
|
||
os << buf; | ||
os.write(buf, len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done to bypass any formatting features of ostringstream (idem the next one). |
||
return *this; | ||
} | ||
}; | ||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow these values have never been initialized. Since UDT. |
||
{ | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That old version with so much of messing around was unncessary. Even if the state clearing after a single value was in plans before C++98, it was finally decided that the flags are changed permanently by manipultors. |
||
|
||
// 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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and below: by some reason clang strictly requires that |
||
|
||
void Stop() | ||
{ | ||
|
@@ -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. | ||
|
@@ -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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,4 +120,20 @@ void TargetMedium::Runner() | |
} | ||
} | ||
|
||
bool TargetMedium::Schedule(const MediaPacket& data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was moved here in order to not pollute the header file. |
||
{ | ||
LOGP(applog.Debug, "TargetMedium::Schedule LOCK ... "); | ||
std::lock_guard<std::mutex> 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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
#include <exception> | ||
#include <thread> | ||
#include <mutex> | ||
#include <atomic> | ||
#include <condition_variable> | ||
|
||
#include "testmedia.hpp" | ||
|
@@ -29,7 +28,7 @@ struct Medium | |
std::mutex buffer_lock; | ||
std::thread thr; | ||
std::condition_variable ready; | ||
std::atomic<bool> running = {false}; | ||
srt::sync::atomic<bool> running {false}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, in all SRT applications, which also use internal SRT facilities, the |
||
std::exception_ptr xp; // To catch exception thrown by a thread | ||
|
||
virtual void Runner() = 0; | ||
|
@@ -147,22 +146,7 @@ struct TargetMedium: Medium<Target> | |
{ | ||
void Runner() override; | ||
|
||
bool Schedule(const MediaPacket& data) | ||
{ | ||
LOGP(applog.Debug, "TargetMedium::Schedule LOCK ... "); | ||
std::lock_guard<std::mutex> 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() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to prevent the compiler from compiling in any other version than exactly C++11.