Skip to content

Commit

Permalink
Removed srt::isgroup. Reused CUDT::isgroup where applicable. Added mi…
Browse files Browse the repository at this point in the history
…ssing license heading.
  • Loading branch information
Mikołaj Małecki committed Feb 20, 2024
1 parent d28e3b2 commit be302ca
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
28 changes: 28 additions & 0 deletions common/devel_util.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/*
* SRT - Secure, Reliable, Transport
* Copyright (c) 2018 Haivision Systems Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

/*****************************************************************************
written by
Haivision Systems Inc.
*****************************************************************************/

// IMPORTANT!!!
//
// This is normally not a part of SRT source files. This is a developer utility
// that allows developers to perform a compile test on a version instrumented
// with type checks. To do that, you can do one of two things:
//
// - configure the compiling process with extra -DSRT_TEST_FORCED_CONSTANT=1 flag
// - unblock the commented out #define in srt.h file for that constant
//
// Note that there's no use of such a compiled code. This is done only so that
// the compiler can detect any misuses of the SRT symbolic type names and
// constants.


#include <ostream>

Expand Down
28 changes: 14 additions & 14 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ SRTSTATUS srt::CUDTUnited::installConnectHook(const SRTSOCKET u, srt_connect_cal
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);
k.group->installConnectHook(hook, opaq);
Expand Down Expand Up @@ -1214,7 +1214,7 @@ SRTSOCKET srt::CUDTUnited::connect(SRTSOCKET u, const sockaddr* srcname, const s
// Check affiliation of the socket. It's now allowed for it to be
// a group or socket. For a group, add automatically a socket to
// the group.
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);
// Note: forced_isn is ignored when connecting a group.
Expand Down Expand Up @@ -1255,7 +1255,7 @@ SRTSOCKET srt::CUDTUnited::connect(const SRTSOCKET u, const sockaddr* name, int
// Check affiliation of the socket. It's now allowed for it to be
// a group or socket. For a group, add automatically a socket to
// the group.
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);

Expand Down Expand Up @@ -1894,7 +1894,7 @@ void srt::CUDTUnited::connectIn(CUDTSocket* s, const sockaddr_any& target_addr,
SRTSTATUS srt::CUDTUnited::close(const SRTSOCKET u)
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);
k.group->close();
Expand Down Expand Up @@ -2352,7 +2352,7 @@ void srt::CUDTUnited::epoll_clear_usocks(int eid)
void srt::CUDTUnited::epoll_add_usock(const int eid, const SRTSOCKET u, const int* events)
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);
m_EPoll.update_usock(eid, u, events);
Expand Down Expand Up @@ -2430,7 +2430,7 @@ void srt::CUDTUnited::epoll_remove_usock(const int eid, const SRTSOCKET u)

#if ENABLE_BONDING
CUDTGroup* g = 0;
if (isgroup(u))
if (CUDT::isgroup(u))
{
GroupKeeper k(*this, u, ERH_THROW);
g = k.group;
Expand Down Expand Up @@ -3504,7 +3504,7 @@ SRTSOCKET srt::CUDT::getGroupOfSocket(SRTSOCKET socket)

SRTSTATUS srt::CUDT::getGroupData(SRTSOCKET groupid, SRT_SOCKGROUPDATA* pdata, size_t* psize)
{
if (!isgroup(groupid) || !psize)
if (!CUDT::isgroup(groupid) || !psize)
{
return APIError(MJ_NOTSUP, MN_INVAL, 0);
}
Expand Down Expand Up @@ -3675,7 +3675,7 @@ SRTSOCKET srt::CUDT::connectLinks(SRTSOCKET grp, SRT_SOCKGROUPCONFIG targets[],
if (arraysize <= 0)
return APIError(MJ_NOTSUP, MN_INVAL, 0), SRT_INVALID_SOCK;

if (!isgroup(grp))
if (!CUDT::isgroup(grp))
{
// connectLinks accepts only GROUP id, not socket id.
return APIError(MJ_NOTSUP, MN_SIDINVAL, 0), SRT_INVALID_SOCK;
Expand Down Expand Up @@ -3786,7 +3786,7 @@ SRTSTATUS srt::CUDT::getsockopt(SRTSOCKET u, int, SRT_SOCKOPT optname, void* pw_
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
CUDTUnited::GroupKeeper k(uglobal(), u, CUDTUnited::ERH_THROW);
k.group->getOpt(optname, (pw_optval), (*pw_optlen));
Expand Down Expand Up @@ -3817,7 +3817,7 @@ SRTSTATUS srt::CUDT::setsockopt(SRTSOCKET u, int, SRT_SOCKOPT optname, const voi
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
CUDTUnited::GroupKeeper k(uglobal(), u, CUDTUnited::ERH_THROW);
k.group->setOpt(optname, optval, optlen);
Expand Down Expand Up @@ -3862,7 +3862,7 @@ int srt::CUDT::sendmsg2(SRTSOCKET u, const char* buf, int len, SRT_MSGCTRL& w_m)
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
CUDTUnited::GroupKeeper k(uglobal(), u, CUDTUnited::ERH_THROW);
return k.group->send(buf, len, (w_m));
Expand Down Expand Up @@ -3906,7 +3906,7 @@ int srt::CUDT::recvmsg2(SRTSOCKET u, char* buf, int len, SRT_MSGCTRL& w_m)
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
CUDTUnited::GroupKeeper k(uglobal(), u, CUDTUnited::ERH_THROW);
return k.group->recv(buf, len, (w_m));
Expand Down Expand Up @@ -4251,7 +4251,7 @@ srt::CUDTException& srt::CUDT::getlasterror()
SRTSTATUS srt::CUDT::bstats(SRTSOCKET u, CBytePerfMon* perf, bool clear, bool instantaneous)
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
return groupsockbstats(u, perf, clear);
#endif

Expand Down Expand Up @@ -4329,7 +4329,7 @@ SRT_SOCKSTATUS srt::CUDT::getsockstate(SRTSOCKET u)
try
{
#if ENABLE_BONDING
if (isgroup(u))
if (CUDT::isgroup(u))
{
CUDTUnited::GroupKeeper k(uglobal(), u, CUDTUnited::ERH_THROW);
return k.group->getStatus();
Expand Down
6 changes: 0 additions & 6 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ extern "C" {
// socket or a socket group.
static const int32_t SRTGROUP_MASK = (1 << 30);

#ifdef __cplusplus
namespace srt {
inline bool isgroup(SRTSOCKET sid) { return (int32_t(sid) & SRTGROUP_MASK) != 0; }
}
#endif

#ifdef _WIN32
typedef SOCKET SYSSOCKET;
#else
Expand Down
4 changes: 3 additions & 1 deletion srtcore/srt_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ SRTSOCKET srt_connect_bind(SRTSOCKET u,
SRTSTATUS srt_rendezvous(SRTSOCKET u, const struct sockaddr* local_name, int local_namelen,
const struct sockaddr* remote_name, int remote_namelen)
{
if (isgroup(u))
#if ENABLE_BONDING
if (CUDT::isgroup(u))
return CUDT::APIError(MJ_NOTSUP, MN_INVAL, 0);
#endif

bool yes = 1;
CUDT::setsockopt(u, 0, SRTO_RENDEZVOUS, &yes, sizeof yes);
Expand Down
2 changes: 1 addition & 1 deletion testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void SrtCommon::AcceptNewClient()
}

#if ENABLE_BONDING
if (srt::isgroup(m_sock))
if (int32_t(m_sock) & SRTGROUP_MASK)
{
m_listener_group = true;
if (m_group_config != "")
Expand Down
2 changes: 1 addition & 1 deletion testing/testmedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SrtCommon
void Acquire(SRTSOCKET s)
{
m_sock = s;
if (srt::isgroup(s))
if (int32_t(s) & SRTGROUP_MASK)
m_listener_group = true;
}

Expand Down

0 comments on commit be302ca

Please sign in to comment.