Skip to content

Commit

Permalink
[core] Fixed socket group options.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored and maxsharabayko committed Dec 12, 2024
1 parent 1783398 commit ce716be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
29 changes: 27 additions & 2 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)

switch (optName)
{
// First go options that are NOT ALLOWED to be modified on the group.
// (socket-only), or are read-only.

case SRTO_ISN: // read-only
case SRTO_STATE: // read-only
case SRTO_EVENT: // read-only
case SRTO_SNDDATA: // read-only
case SRTO_RCVDATA: // read-only
case SRTO_KMSTATE: // read-only
case SRTO_VERSION: // read-only
case SRTO_PEERVERSION: // read-only
case SRTO_SNDKMSTATE:
case SRTO_RCVKMSTATE:
case SRTO_GROUPTYPE: // read-only
LOGC(gmlog.Error, log << "group option setter: this option ("<< int(optName) << ") is read-only");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

case SRTO_SENDER: // deprecated (1.2.0 version legacy)
case SRTO_IPV6ONLY: // link-type specific
case SRTO_RENDEZVOUS: // socket-only
case SRTO_BINDTODEVICE: // socket-specific
case SRTO_GROUPCONNECT: // listener-specific
LOGC(gmlog.Error, log << "group option setter: this option ("<< int(optName) << ") is socket- or link-specific");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

case SRTO_RCVSYN:
m_bSynRecving = cast_optval<bool>(optval, optlen);
return;
Expand All @@ -369,7 +394,7 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
const int min_timeo_ms = (int) CSrtConfig::COMM_DEF_MIN_STABILITY_TIMEOUT_MS;
if (val_ms < min_timeo_ms)
{
LOGC(qmlog.Error,
LOGC(gmlog.Error,
log << "group option: SRTO_GROUPMINSTABLETIMEO min allowed value is " << min_timeo_ms << " ms.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
Expand All @@ -385,7 +410,7 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)

if (val_ms > idletmo)
{
LOGC(qmlog.Error,
LOGC(gmlog.Error,
log << "group option: SRTO_GROUPMINSTABLETIMEO=" << val_ms << " exceeds SRTO_PEERIDLETIMEO=" << idletmo);
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ typedef enum SRT_SOCKOPT {
SRTO_RCVTIMEO = 14, // recv() timeout
SRTO_REUSEADDR = 15, // reuse an existing port or create a new one
SRTO_MAXBW = 16, // maximum bandwidth (bytes per second) that the connection can use
SRTO_STATE = 17, // current socket state, see UDTSTATUS, read only
SRTO_STATE = 17, // current socket state, see SRT_SOCKSTATUS, read only
SRTO_EVENT = 18, // current available events associated with the socket
SRTO_SNDDATA = 19, // size of data in the sending buffer
SRTO_RCVDATA = 20, // size of data available for recv
Expand Down
10 changes: 5 additions & 5 deletions test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ TEST(Bonding, Options)
TestInit srtinit;

// Create a group
const SRTSOCKET grp = srt_create_group(SRT_GTYPE_BROADCAST);
MAKE_UNIQUE_SOCK(grp, "broadcast group", srt_create_group(SRT_GTYPE_BROADCAST));

// rendezvous shall not be allowed to be set on the group
// XXX actually it is possible, but no one tested it. POSTPONE.
Expand Down Expand Up @@ -437,9 +437,10 @@ TEST(Bonding, Options)
// First wait - until it's let go with accepting
latch.wait(ux);

sockaddr_any revsa;
SRTSOCKET gs = srt_accept(lsn, revsa.get(), &revsa.len);
ASSERT_NE(gs, SRT_ERROR);
//sockaddr_any revsa;
SRTSOCKET lsna [1] = { lsn };
SRTSOCKET gs = srt_accept_bond(lsna, 1, 1000);
ASSERT_NE(gs, SRT_INVALID_SOCK);

check_streamid(gs);

Expand Down Expand Up @@ -541,7 +542,6 @@ TEST(Bonding, Options)
}

accept_and_close.join();
srt_close(grp);
}

inline SRT_SOCKGROUPCONFIG PrepareEndpoint(const std::string& host, int port)
Expand Down

0 comments on commit ce716be

Please sign in to comment.