From 5f7ea28f111a1b43841a7262e4b24782f60cc723 Mon Sep 17 00:00:00 2001 From: Mikolaj Malecki Date: Mon, 9 Sep 2024 14:39:35 +0200 Subject: [PATCH] [maint] Moved debug-related functions to common --- srtcore/common.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ srtcore/common.h | 19 ++---------------- srtcore/epoll.cpp | 31 ------------------------------ 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/srtcore/common.cpp b/srtcore/common.cpp index 6d747ecaa..d3fd4f22c 100644 --- a/srtcore/common.cpp +++ b/srtcore/common.cpp @@ -461,6 +461,54 @@ bool SrtParseConfig(const string& s, SrtConfig& w_config) return true; } + +std::string FormatLossArray(const std::vector< std::pair >& lra) +{ + std::ostringstream os; + + os << "[ "; + for (std::vector< std::pair >::const_iterator i = lra.begin(); i != lra.end(); ++i) + { + int len = CSeqNo::seqoff(i->first, i->second); + os << "%" << i->first; + if (len > 1) + os << "+" << len; + os << " "; + } + + os << "]"; + return os.str(); +} + +ostream& PrintEpollEvent(ostream& os, int events, int et_events) +{ + static pair const namemap [] = { + make_pair(SRT_EPOLL_IN, "R"), + make_pair(SRT_EPOLL_OUT, "W"), + make_pair(SRT_EPOLL_ERR, "E"), + make_pair(SRT_EPOLL_UPDATE, "U") + }; + bool any = false; + + const int N = (int)Size(namemap); + + for (int i = 0; i < N; ++i) + { + if (events & namemap[i].first) + { + os << "["; + if (et_events & namemap[i].first) + os << "^"; + os << namemap[i].second << "]"; + any = true; + } + } + + if (!any) + os << "[]"; + + return os; +} } // namespace srt namespace srt_logging diff --git a/srtcore/common.h b/srtcore/common.h index 6a8912118..ff84c3faf 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -1435,23 +1435,8 @@ inline bool checkMappedIPv4(const sockaddr_in6& sa) return checkMappedIPv4(addr); } -inline std::string FormatLossArray(const std::vector< std::pair >& lra) -{ - std::ostringstream os; - - os << "[ "; - for (std::vector< std::pair >::const_iterator i = lra.begin(); i != lra.end(); ++i) - { - int len = CSeqNo::seqoff(i->first, i->second); - os << "%" << i->first; - if (len > 1) - os << "+" << len; - os << " "; - } - - os << "]"; - return os.str(); -} +std::string FormatLossArray(const std::vector< std::pair >& lra); +std::ostream& PrintEpollEvent(std::ostream& os, int events, int et_events = 0); } // namespace srt diff --git a/srtcore/epoll.cpp b/srtcore/epoll.cpp index e2b861bf9..8cd8440c7 100644 --- a/srtcore/epoll.cpp +++ b/srtcore/epoll.cpp @@ -71,12 +71,6 @@ modified by using namespace std; using namespace srt::sync; -#if ENABLE_HEAVY_LOGGING -namespace srt { -static ostream& PrintEpollEvent(ostream& os, int events, int et_events = 0); -} -#endif - namespace srt_logging { extern Logger eilog, ealog; @@ -956,31 +950,6 @@ int srt::CEPoll::update_events(const SRTSOCKET& uid, std::set& eids, const namespace srt { -static ostream& PrintEpollEvent(ostream& os, int events, int et_events) -{ - static pair const namemap [] = { - make_pair(SRT_EPOLL_IN, "R"), - make_pair(SRT_EPOLL_OUT, "W"), - make_pair(SRT_EPOLL_ERR, "E"), - make_pair(SRT_EPOLL_UPDATE, "U") - }; - - const int N = (int)Size(namemap); - - for (int i = 0; i < N; ++i) - { - if (events & namemap[i].first) - { - os << "["; - if (et_events & namemap[i].first) - os << "^"; - os << namemap[i].second << "]"; - } - } - - return os; -} - string DisplayEpollResults(const std::map& sockset) { typedef map fmap_t;