Skip to content

Commit

Permalink
[core] const SrtOptionAction (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Apr 15, 2021
1 parent 9442870 commit 35fb87f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions srtcore/core.cpp
Expand Up @@ -130,11 +130,15 @@ extern const SRT_SOCKOPT srt_post_opt_list [SRT_SOCKOPT_NPOST] = {
SRTO_LOSSMAXTTL
};

static const int32_t
const int32_t
SRTO_R_PREBIND = BIT(0), //< cannot be modified after srt_bind()
SRTO_R_PRE = BIT(1), //< cannot be modified after connection is established
SRTO_POST_SPEC = BIT(2); //< executes some action after setting the option


namespace srt
{

struct SrtOptionAction
{
int flags[SRTO_E_SIZE];
Expand Down Expand Up @@ -210,8 +214,11 @@ struct SrtOptionAction
// passed to a setting function.
private_default[SRTO_STREAMID] = string();
}
}
srt_options_action;
};

const SrtOptionAction s_sockopt_action;

} // namespace srt


void CUDT::construct()
Expand Down Expand Up @@ -297,9 +304,9 @@ CUDT::CUDT(CUDTSocket* parent, const CUDT& ancestor): m_parent(parent)
m_config = ancestor.m_config;
// Reset values that shall not be derived to default ones.
// These declarations should be consistent with SRTO_R_PRIVATE flag.
for (size_t i = 0; i < Size(srt_options_action.flags); ++i)
for (size_t i = 0; i < Size(s_sockopt_action.flags); ++i)
{
string* pdef = map_getp(srt_options_action.private_default, SRT_SOCKOPT(i));
const string* pdef = map_getp(s_sockopt_action.private_default, SRT_SOCKOPT(i));
if (pdef)
{
try
Expand Down Expand Up @@ -342,12 +349,12 @@ void CUDT::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
if (m_bBroken || m_bClosing)
throw CUDTException(MJ_CONNECTION, MN_CONNLOST, 0);

// Match check (confirm optName as index for srt_options_action)
// Match check (confirm optName as index for s_sockopt_action)
if (int(optName) < 0 || int(optName) >= int(SRTO_E_SIZE))
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

// Restriction check
const int oflags = srt_options_action.flags[optName];
const int oflags = s_sockopt_action.flags[optName];

ScopedLock cg (m_ConnectionLock);
ScopedLock sendguard (m_SendLock);
Expand Down
6 changes: 3 additions & 3 deletions srtcore/sync_posix.cpp
Expand Up @@ -38,7 +38,7 @@ namespace srt
namespace sync
{

void rdtsc(uint64_t& x)
static void rdtsc(uint64_t& x)
{
#if SRT_SYNC_CLOCK == SRT_SYNC_CLOCK_IA32_RDTSC
uint32_t lval, hval;
Expand Down Expand Up @@ -123,9 +123,9 @@ static int count_subsecond_precision(int64_t ticks_per_us)
return signs;
}

static const int64_t s_clock_ticks_per_us = get_cpu_frequency();
const int64_t s_clock_ticks_per_us = get_cpu_frequency();

static const int s_clock_subsecond_precision = count_subsecond_precision(s_clock_ticks_per_us);
const int s_clock_subsecond_precision = count_subsecond_precision(s_clock_ticks_per_us);

int clockSubsecondPrecision() { return s_clock_subsecond_precision; }

Expand Down

0 comments on commit 35fb87f

Please sign in to comment.