From 3d108fa75278b6e23dabb92951d2527012439415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Thu, 18 Jul 2024 16:57:18 +0200 Subject: [PATCH] Applied fixes from code review --- srtcore/api.cpp | 13 ++++++------- srtcore/api.h | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/srtcore/api.cpp b/srtcore/api.cpp index ea7451f00..e912fb082 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -1916,11 +1916,11 @@ int srt::CUDTUnited::close(const SRTSOCKET u) #if ENABLE_HEAVY_LOGGING // Wrapping the log into a destructor so that it // is printed AFTER the destructor of SocketKeeper. - struct ForceDestructor + struct ScopedExitLog { - CUDTSocket* ps; - ForceDestructor(): ps(NULL){} - ~ForceDestructor() + const CUDTSocket* const ps; + ScopedExitLog(const CUDTSocket* p): ps(p){} + ~ScopedExitLog() { if (ps) // Could be not acquired by SocketKeeper, occasionally { @@ -1931,11 +1931,10 @@ int srt::CUDTUnited::close(const SRTSOCKET u) #endif SocketKeeper k(*this, u, ERH_THROW); - IF_HEAVY_LOGGING(fod.ps = k.socket); + IF_HEAVY_LOGGING(ScopedExitLog slog(k.socket)); HLOGC(smlog.Debug, log << "CUDTUnited::close/begin: @" << u << " busy=" << k.socket->isStillBusy()); - int ret = close(k.socket); - return ret; + return close(k.socket); } #if ENABLE_BONDING diff --git a/srtcore/api.h b/srtcore/api.h index bac6ae026..6addfbfa2 100644 --- a/srtcore/api.h +++ b/srtcore/api.h @@ -337,7 +337,7 @@ class CUDTUnited int epoll_release(const int eid); #if ENABLE_BONDING - // [[using locked(m_GlobControlLock)]] + SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_GlobControlLock) CUDTGroup& addGroup(SRTSOCKET id, SRT_GROUP_TYPE type) { // This only ensures that the element exists. @@ -359,7 +359,7 @@ class CUDTUnited void deleteGroup(CUDTGroup* g); void deleteGroup_LOCKED(CUDTGroup* g); - // [[using locked(m_GlobControlLock)]] + SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_GlobControlLock) CUDTGroup* findPeerGroup_LOCKED(SRTSOCKET peergroup) { for (groups_t::iterator i = m_Groups.begin(); i != m_Groups.end(); ++i) @@ -485,7 +485,7 @@ class CUDTUnited // This is only for a use together with an empty constructor. bool acquire(CUDTUnited& glob, CUDTSocket* s) { - bool caught = glob.acquireSocket(s); + const bool caught = glob.acquireSocket(s); socket = caught ? s : NULL; return caught; }