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

[BUG] Filling group data now done by a common procedure #1553

Merged
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
90 changes: 37 additions & 53 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,18 +1573,7 @@ int CUDTGroup::sendBroadcast(const char* buf, int len, SRT_MSGCTRL& w_mc)
if (w_mc.grpdata)
{
// Enough space to fill
w_mc.grpdata[i].id = d->id;
w_mc.grpdata[i].sockstate = d->laststatus;
w_mc.grpdata[i].memberstate = d->sndstate;

if (d->sndstate == SRT_GST_RUNNING)
w_mc.grpdata[i].result = rstat; // The same result for all sockets, if running
else if (d->sndstate == SRT_GST_IDLE)
w_mc.grpdata[i].result = 0;
else
w_mc.grpdata[i].result = -1;

memcpy((&w_mc.grpdata[i].peeraddr), &d->peer, d->peer.size());
copyGroupData(*d, (w_mc.grpdata[i]));
}

// We perform this loop anyway because we still need to check if any
Expand Down Expand Up @@ -1632,41 +1621,47 @@ int CUDTGroup::getGroupData(SRT_SOCKGROUPDATA* pdata, size_t* psize)
size_t i = 0;
for (gli_t d = m_Group.begin(); d != m_Group.end(); ++d, ++i)
{
pdata[i].id = d->id;
memcpy((&pdata[i].peeraddr), &d->peer, d->peer.size());
copyGroupData(*d, (pdata[i]));
}

pdata[i].sockstate = d->laststatus;
pdata[i].token = d->token;
return m_Group.size();
}

// In the internal structure the member state
// is one per direction. From the user perspective
// however it is used either in one direction only,
// in which case the one direction that is active
// matters, or in both directions, in which case
// it will be always either both active or both idle.
void CUDTGroup::copyGroupData(const CUDTGroup::SocketData& source, SRT_SOCKGROUPDATA& w_target)
{
w_target.id = source.id;
memcpy((&w_target.peeraddr), &source.peer, source.peer.size());

if (d->sndstate == SRT_GST_RUNNING || d->rcvstate == SRT_GST_RUNNING)
{
pdata[i].result = 0;
pdata[i].memberstate = SRT_GST_RUNNING;
}
// Stats can differ per direction only
// when at least in one direction it's ACTIVE.
else if (d->sndstate == SRT_GST_BROKEN)
{
pdata[i].result = -1;
pdata[i].memberstate = SRT_GST_BROKEN;
}
else
{
pdata[i].result = 0;
pdata[i].memberstate = d->sndstate;
}
w_target.sockstate = source.laststatus;
w_target.token = source.token;

// In the internal structure the member state
// is one per direction. From the user perspective
// however it is used either in one direction only,
// in which case the one direction that is active
// matters, or in both directions, in which case
// it will be always either both active or both idle.

pdata[i].weight = d->weight;
if (source.sndstate == SRT_GST_RUNNING || source.rcvstate == SRT_GST_RUNNING)
{
w_target.result = 0;
w_target.memberstate = SRT_GST_RUNNING;
}
// Stats can differ per direction only
// when at least in one direction it's ACTIVE.
else if (source.sndstate == SRT_GST_BROKEN || source.rcvstate == SRT_GST_BROKEN)
{
w_target.result = -1;
w_target.memberstate = SRT_GST_BROKEN;
}
else
{
// IDLE or PENDING
w_target.result = 0;
w_target.memberstate = source.sndstate;
}

return m_Group.size();
w_target.weight = source.weight;
}

void CUDTGroup::getGroupCount(size_t& w_size, bool& w_still_alive)
Expand Down Expand Up @@ -3847,18 +3842,7 @@ int CUDTGroup::sendBackup(const char* buf, int len, SRT_MSGCTRL& w_mc)
if (w_mc.grpdata)
{
// Enough space to fill
w_mc.grpdata[i].id = d->id;
w_mc.grpdata[i].sockstate = d->laststatus;
w_mc.grpdata[i].memberstate = d->sndstate;

if (d->sndstate == SRT_GST_RUNNING)
w_mc.grpdata[i].result = d->sndresult;
else if (d->sndstate == SRT_GST_IDLE)
w_mc.grpdata[i].result = 0;
else
w_mc.grpdata[i].result = -1;

memcpy((&w_mc.grpdata[i].peeraddr), &d->peer, d->peer.size());
copyGroupData(*d, (w_mc.grpdata[i]));
}

// We perform this loop anyway because we still need to check if any
Expand Down
2 changes: 2 additions & 0 deletions srtcore/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ class CUDTGroup
const SRT_MSGCTRL& in //< MSGCTRL read from the data-providing socket
);

void copyGroupData(const CUDTGroup::SocketData& source, SRT_SOCKGROUPDATA& w_target);

#if ENABLE_HEAVY_LOGGING
void debugGroup();
#else
Expand Down