Skip to content
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] Minor refactoring around strerror_array_sizes #1987

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions srtcore/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down
10 changes: 5 additions & 5 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 40 additions & 40 deletions srtcore/group_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*
*/

/*****************************************************************************
Written by
Haivision Systems Inc.
*****************************************************************************/
/*****************************************************************************
Written by
Haivision Systems Inc.
*****************************************************************************/

#include "platform_sys.h"

Expand All @@ -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
69 changes: 34 additions & 35 deletions srtcore/group_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SocketData> 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<SocketData> group_t;
typedef group_t::iterator gli_t;

} // namespace groups
} // namespace srt

#endif // INC_SRT_GROUP_COMMON_H
27 changes: 11 additions & 16 deletions srtcore/strerror_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down