diff --git a/srtcore/api.cpp b/srtcore/api.cpp index 71e4a8772..5bd307125 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -165,14 +165,14 @@ bool CUDTSocket::readReady() return broken(); } -bool CUDTSocket::writeReady() +bool CUDTSocket::writeReady() const { return (m_pUDT->m_bConnected && (m_pUDT->m_pSndBuffer->getCurrBufSize() < m_pUDT->m_config.iSndBufSize)) || broken(); } -bool CUDTSocket::broken() +bool CUDTSocket::broken() const { return m_pUDT->m_bBroken || !m_pUDT->m_bConnected; } diff --git a/srtcore/api.h b/srtcore/api.h index 604f14a99..4ca299b24 100644 --- a/srtcore/api.h +++ b/srtcore/api.h @@ -182,8 +182,8 @@ class CUDTSocket // Instrumentally used by select() and also required for non-blocking // mode check in groups bool readReady(); - bool writeReady(); - bool broken(); + bool writeReady() const; + bool broken() const; private: CUDTSocket(const CUDTSocket&); diff --git a/srtcore/core.cpp b/srtcore/core.cpp index c87efeb42..80a787d7c 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -3115,7 +3115,7 @@ bool CUDT::interpretGroup(const int32_t groupdata[], size_t data_size SRT_ATR_UN return false; } - srt::groups::SocketData* f = m_parent->m_GroupMemberData; + groups::SocketData* f = m_parent->m_GroupMemberData; f->weight = link_weight; f->agent = m_parent->m_SelfAddr; @@ -3214,7 +3214,7 @@ SRTSOCKET CUDT::makeMePeerOf(SRTSOCKET peergroup, SRT_GROUP_TYPE gtp, uint32_t l // Copy of addSocketToGroup. No idea how many parts could be common, not much. // Check if the socket already is in the group - srt::groups::SocketData* f; + groups::SocketData* f; if (gp->contains(m_SocketID, (f))) { // XXX This is internal error. Report it, but continue @@ -4650,7 +4650,7 @@ EConnectStatus CUDT::postConnect(const CPacket &response, bool rendezvous, CUDTE HLOGC(cnlog.Debug, log << "group: Socket @" << m_parent->m_SocketID << " fresh connected, setting IDLE"); - srt::groups::SocketData* gi = m_parent->m_GroupMemberData; + groups::SocketData* gi = m_parent->m_GroupMemberData; gi->sndstate = SRT_GST_IDLE; gi->rcvstate = SRT_GST_IDLE; gi->laststatus = SRTS_CONNECTED; @@ -9483,7 +9483,7 @@ int CUDT::processData(CUnit* in_unit) if (m_parent->m_GroupOf) { ScopedLock protect_group_existence (s_UDTUnited.m_GlobControlLock); - srt::groups::SocketData* gi = m_parent->m_GroupMemberData; + groups::SocketData* gi = m_parent->m_GroupMemberData; // This check is needed as after getting the lock the socket // could be potentially removed. It is however granted that as long @@ -9982,7 +9982,7 @@ CUDT::loss_seqs_t CUDT::defaultPacketArrival(void* vself, CPacket& pkt) if (self->m_parent->m_GroupOf) { - srt::groups::SocketData* gi = self->m_parent->m_GroupMemberData; + groups::SocketData* gi = self->m_parent->m_GroupMemberData; if (gi->rcvstate < SRT_GST_RUNNING) // PENDING or IDLE, tho PENDING is unlikely { HLOGC(qrlog.Debug, log << "defaultPacketArrival: IN-GROUP rcv state transition to RUNNING. NOT checking for loss"); diff --git a/srtcore/core.h b/srtcore/core.h index dbb1ab5f9..2f97d9cfc 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -1046,7 +1046,7 @@ class CUDT int64_t m_sndDurationTotal; // total real time for sending - time_point tsLastSampleTime; // last performance sample time + time_point tsLastSampleTime; // last performance sample time int64_t traceSent; // number of packets sent in the last trace interval int64_t traceSentUniq; // number of original packets sent in the last trace interval int64_t traceRecv; // number of packets received in the last trace interval diff --git a/srtcore/group_common.cpp b/srtcore/group_common.cpp index 513e5065c..8716e343a 100644 --- a/srtcore/group_common.cpp +++ b/srtcore/group_common.cpp @@ -8,10 +8,10 @@ * */ - /***************************************************************************** - Written by - Haivision Systems Inc. - *****************************************************************************/ +/***************************************************************************** +Written by + Haivision Systems Inc. +*****************************************************************************/ #include "platform_sys.h" @@ -20,43 +20,43 @@ namespace srt { - namespace groups - { +namespace groups +{ - SocketData prepareSocketData(CUDTSocket* s) - { - // This uses default SRT_GST_BROKEN because when the group operation is done, - // then the SRT_GST_IDLE state automatically turns into SRT_GST_RUNNING. This is - // recognized as an initial state of the fresh added socket to the group, - // so some "initial configuration" must be done on it, after which it's - // turned into SRT_GST_RUNNING, that is, it's treated as all others. When - // set to SRT_GST_BROKEN, this socket is disregarded. This socket isn't cleaned - // up, however, unless the status is simultaneously SRTS_BROKEN. +SocketData prepareSocketData(CUDTSocket* s) +{ + // This uses default SRT_GST_BROKEN because when the group operation is done, + // then the SRT_GST_IDLE state automatically turns into SRT_GST_RUNNING. This is + // recognized as an initial state of the fresh added socket to the group, + // so some "initial configuration" must be done on it, after which it's + // turned into SRT_GST_RUNNING, that is, it's treated as all others. When + // set to SRT_GST_BROKEN, this socket is disregarded. This socket isn't cleaned + // up, however, unless the status is simultaneously SRTS_BROKEN. - // The order of operations is then: - // - add the socket to the group in this "broken" initial state - // - connect the socket (or get it extracted from accept) - // - update the socket state (should be SRTS_CONNECTED) - // - once the connection is established (may take time with connect), set SRT_GST_IDLE - // - the next operation of send/recv will automatically turn it into SRT_GST_RUNNING - SocketData sd = { - s->m_SocketID, - s, - -1, - SRTS_INIT, - SRT_GST_BROKEN, - SRT_GST_BROKEN, - -1, - -1, - sockaddr_any(), - sockaddr_any(), - false, - false, - false, - 0 // weight - }; - return sd; - } + // The order of operations is then: + // - add the socket to the group in this "broken" initial state + // - connect the socket (or get it extracted from accept) + // - update the socket state (should be SRTS_CONNECTED) + // - once the connection is established (may take time with connect), set SRT_GST_IDLE + // - the next operation of send/recv will automatically turn it into SRT_GST_RUNNING + SocketData sd = { + s->m_SocketID, + s, + -1, + SRTS_INIT, + SRT_GST_BROKEN, + SRT_GST_BROKEN, + -1, + -1, + sockaddr_any(), + sockaddr_any(), + false, + false, + false, + 0 // weight + }; + return sd; +} - } // namespace groups +} // namespace groups } // namespace srt diff --git a/srtcore/group_common.h b/srtcore/group_common.h index 13ef4ad4a..f6ac123c6 100644 --- a/srtcore/group_common.h +++ b/srtcore/group_common.h @@ -8,10 +8,10 @@ * */ - /***************************************************************************** - Written by - Haivision Systems Inc. - *****************************************************************************/ +/***************************************************************************** +Written by + Haivision Systems Inc. +*****************************************************************************/ #ifndef INC_SRT_GROUP_COMMON_H #define INC_SRT_GROUP_COMMON_H @@ -24,37 +24,36 @@ namespace srt { - namespace groups - { - typedef SRT_MEMBERSTATUS GroupState; - - struct SocketData - { - SRTSOCKET id; // same as ps->m_SocketID - CUDTSocket* ps; - int token; - SRT_SOCKSTATUS laststatus; - GroupState sndstate; - GroupState rcvstate; - int sndresult; - int rcvresult; - sockaddr_any agent; - sockaddr_any peer; - bool ready_read; - bool ready_write; - bool ready_error; - - // Configuration - uint16_t weight; - }; - - SocketData prepareSocketData(CUDTSocket* s); - - typedef std::list group_t; - typedef group_t::iterator gli_t; - - } // namespace groups -} // namespace srt +namespace groups +{ +typedef SRT_MEMBERSTATUS GroupState; +struct SocketData +{ + SRTSOCKET id; // same as ps->m_SocketID + CUDTSocket* ps; + int token; + SRT_SOCKSTATUS laststatus; + GroupState sndstate; + GroupState rcvstate; + int sndresult; + int rcvresult; + sockaddr_any agent; + sockaddr_any peer; + bool ready_read; + bool ready_write; + bool ready_error; + + // Configuration + uint16_t weight; +}; + +SocketData prepareSocketData(CUDTSocket* s); + +typedef std::list group_t; +typedef group_t::iterator gli_t; + +} // namespace groups +} // namespace srt #endif // INC_SRT_GROUP_COMMON_H diff --git a/srtcore/strerror_defs.cpp b/srtcore/strerror_defs.cpp index ee32527bf..c37ee276d 100644 --- a/srtcore/strerror_defs.cpp +++ b/srtcore/strerror_defs.cpp @@ -119,27 +119,22 @@ const char** strerror_array_major [] = { strerror_msgs_again, // MJ_AGAIN = 6 strerror_msgs_peererror, // MJ_PEERERROR = 7 NULL - }; - - -size_t strerror_array_sizes [] = { - 1, - 6, - 3, - 4, - 5, - 15, - 5, - 1, +#define SRT_ARRAY_SIZE(ARR) sizeof(ARR) / sizeof(ARR[0]) + +const size_t strerror_array_sizes[] = { + SRT_ARRAY_SIZE(strerror_msgs_success) - 1, + SRT_ARRAY_SIZE(strerror_msgs_setup) - 1, + SRT_ARRAY_SIZE(strerror_msgs_connection) - 1, + SRT_ARRAY_SIZE(strerror_msgs_systemres) - 1, + SRT_ARRAY_SIZE(strerror_msgs_filesystem) - 1, + SRT_ARRAY_SIZE(strerror_msgs_notsup) - 1, + SRT_ARRAY_SIZE(strerror_msgs_again) - 1, + SRT_ARRAY_SIZE(strerror_msgs_peererror) - 1, 0 - }; - - - const char* strerror_get_message(size_t major, size_t minor) { static const char* const undefined = "UNDEFINED ERROR";