Skip to content

Commit

Permalink
[core] Fixed type conversion build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Apr 23, 2021
1 parent 3bf5ceb commit 90c62af
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,10 @@ unique_ptr<Medium> TcpMedium::Accept()

// Configure 1s timeout
timeval timeout_1s { 1, 0 };
int st = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout_1s, sizeof timeout_1s);
int st SRT_ATR_UNUSED = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout_1s, sizeof timeout_1s);
timeval re;
socklen_t size = sizeof re;
int st2 = getsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&re, &size);
int st2 SRT_ATR_UNUSED = getsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&re, &size);

LOGP(applog.Debug, "Setting SO_RCVTIMEO to @", m_socket, ": ", st == -1 ? "FAILED" : "SUCCEEDED",
", read-back value: ", st2 == -1 ? int64_t(-1) : (int64_t(re.tv_sec)*1000000 + re.tv_usec)/1000, "ms");
Expand Down
4 changes: 2 additions & 2 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ steady_clock::time_point CRcvBuffer::getTsbPdTimeBase(uint32_t timestamp_us)
{
carryover = int64_t(CPacket::MAX_TIMESTAMP) + 1;
}
//
else if ((timestamp_us >= TSBPD_WRAP_PERIOD) && (timestamp_us <= (TSBPD_WRAP_PERIOD * 2)))
// timestamp_us >= TSBPD_WRAP_PERIOD
else if (timestamp_us <= (TSBPD_WRAP_PERIOD * 2))
{
/* Exiting wrap check period (if for packet delivery head) */
m_bTsbPdWrapCheck = false;
Expand Down
6 changes: 5 additions & 1 deletion srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,17 @@ void CChannel::createSocket(int family)

if ((m_mcfg.iIpV6Only != -1) && (family == AF_INET6)) // (not an error if it fails)
{
int res ATR_UNUSED = ::setsockopt(m_iSocket, IPPROTO_IPV6, IPV6_V6ONLY,
const int res ATR_UNUSED = ::setsockopt(m_iSocket, IPPROTO_IPV6, IPV6_V6ONLY,
(const char*) &m_mcfg.iIpV6Only, sizeof m_mcfg.iIpV6Only);
#if ENABLE_LOGGING
if (res == -1)
{
int err = errno;
char msg[160];
LOGC(kmlog.Error, log << "::setsockopt: failed to set IPPROTO_IPV6/IPV6_V6ONLY = "
<< m_mcfg.iIpV6Only << ": " << SysStrError(err, msg, 159));
}
#endif // ENABLE_LOGGING
}

}
Expand Down Expand Up @@ -352,9 +354,11 @@ void CChannel::setUDPSockOpt()
if (0 != ::setsockopt(m_iSocket, SOL_SOCKET, SO_BINDTODEVICE,
m_mcfg.sBindToDevice.c_str(), m_mcfg.sBindToDevice.size()))
{
#if ENABLE_LOGGING
char buf[255];
const char* err = SysStrError(NET_ERROR, buf, 255);
LOGC(kmlog.Error, log << "setsockopt(SRTO_BINDTODEVICE): " << err);
#endif // ENABLE_LOGGING
throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR);
}
}
Expand Down
18 changes: 9 additions & 9 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ CUDT::CUDT(CUDTSocket* parent, const CUDT& ancestor): m_parent(parent)
{
// Ignore errors here - this is a development-time granted
// value, not user-provided value.
m_config.set(SRT_SOCKOPT(i), pdef->data(), pdef->size());
m_config.set(SRT_SOCKOPT(i), pdef->data(), (int) pdef->size());
}
catch (...)
{
Expand Down Expand Up @@ -6567,7 +6567,7 @@ int CUDT::receiveMessage(char* data, int len, SRT_MSGCTRL& w_mctrl, int by_excep

// After signaling the tsbpd for ready data, report the bandwidth.
#if ENABLE_HEAVY_LOGGING
double bw = Bps2Mbps( m_iBandwidth * m_iMaxSRTPayloadSize );
double bw = Bps2Mbps(int64_t(m_iBandwidth) * m_iMaxSRTPayloadSize );
HLOGC(arlog.Debug, log << CONID() << "CURRENT BANDWIDTH: " << bw << "Mbps (" << m_iBandwidth << " buffers per second)");
#endif
}
Expand Down Expand Up @@ -7024,10 +7024,10 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
perf->pktRcvUndecryptTotal = m_stats.m_rcvUndecryptTotal;
perf->byteRcvUndecryptTotal = m_stats.m_rcvBytesUndecryptTotal;

double interval = count_microseconds(currtime - m_stats.tsLastSampleTime);
const double interval = (double) count_microseconds(currtime - m_stats.tsLastSampleTime);
perf->mbpsSendRate = double(perf->byteSent) * 8.0 / interval;
perf->mbpsRecvRate = double(perf->byteRecv) * 8.0 / interval;
perf->usPktSndPeriod = count_microseconds(m_tdSendInterval);
perf->usPktSndPeriod = (double) count_microseconds(m_tdSendInterval);
perf->pktFlowWindow = m_iFlowWindowSize;
perf->pktCongestionWindow = (int)m_dCongestionWindow;
perf->pktFlightSize = getFlightSpan();
Expand Down Expand Up @@ -7172,9 +7172,9 @@ bool CUDT::updateCC(ETransmissionEvent evt, const EventVariant arg)
// - if SRTO_MAXBW == 0, use SRTO_INPUTBW + SRTO_OHEADBW
// - if SRTO_INPUTBW == 0, pass 0 to requst in-buffer sampling
// Bytes/s
int bw = m_config.llMaxBW != 0 ? m_config.llMaxBW : // When used SRTO_MAXBW
m_config.llInputBW != 0 ? withOverhead(m_config.llInputBW) : // SRTO_INPUTBW + SRT_OHEADBW
0; // When both MAXBW and INPUTBW are 0, request in-buffer sampling
const int64_t bw = m_config.llMaxBW != 0 ? m_config.llMaxBW : // When used SRTO_MAXBW
m_config.llInputBW != 0 ? withOverhead(m_config.llInputBW) : // SRTO_INPUTBW + SRT_OHEADBW
0; // When both MAXBW and INPUTBW are 0, request in-buffer sampling

// Note: setting bw == 0 uses BW_INFINITE value in LiveCC
m_CongCtl->updateBandwidth(m_config.llMaxBW, bw);
Expand Down Expand Up @@ -9408,12 +9408,12 @@ int CUDT::processData(CUnit* in_unit)
{
IF_HEAVY_LOGGING(exc_type = "BELATED");
steady_clock::time_point tsbpdtime = m_pRcvBuffer->getPktTsbPdTime(rpkt.getMsgTimeStamp());
long bltime = CountIIR<uint64_t>(
const double bltime = (double) CountIIR<uint64_t>(
uint64_t(m_stats.traceBelatedTime) * 1000,
count_microseconds(steady_clock::now() - tsbpdtime), 0.2);

enterCS(m_StatsLock);
m_stats.traceBelatedTime = double(bltime) / 1000.0;
m_stats.traceBelatedTime = bltime / 1000.0;
m_stats.traceRcvBelated++;
leaveCS(m_StatsLock);
HLOGC(qrlog.Debug,
Expand Down
16 changes: 4 additions & 12 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class CUDT

int minSndSize(int len = 0) const
{
const int ps = maxPayloadSize();
const int ps = (int) maxPayloadSize();
if (len == 0) // wierd, can't use non-static data member as default argument!
len = ps;
return m_config.bMessageAPI ? (len+ps-1)/ps : 1;
Expand All @@ -379,7 +379,7 @@ class CUDT
// So, this can be simply defined as: TS = (RTS - STS) % (MAX_TIMESTAMP+1)
// XXX Would be nice to check if local_time > m_tsStartTime,
// otherwise it may go unnoticed with clock skew.
return srt::sync::count_microseconds(from_time - m_stats.tsStartTime);
return (int32_t) srt::sync::count_microseconds(from_time - m_stats.tsStartTime);
}

void setPacketTS(CPacket& p, const time_point& local_time)
Expand All @@ -400,18 +400,10 @@ class CUDT
{
using namespace srt::sync;
// Random Initial Sequence Number (normal mode)
srand(count_microseconds(steady_clock::now().time_since_epoch()));
srand((unsigned) count_microseconds(steady_clock::now().time_since_epoch()));
return (int32_t)(CSeqNo::m_iMaxSeqNo * (double(rand()) / RAND_MAX));
}

// XXX See CUDT::tsbpd() to see how to implement it. This should
// do the same as TLPKTDROP feature when skipping packets that are agreed
// to be lost. Note that this is predicted to be called with TSBPD off.
// This is to be exposed for the application so that it can require this
// sequence to be skipped, if that packet has been otherwise arrived through
// a different channel.
void skipIncoming(int32_t seq);

// For SRT_tsbpdLoop
static CUDTUnited* uglobal() { return &s_UDTUnited; } // needed by tsbpdLoop
std::set<int>& pollset() { return m_sPollID; }
Expand Down Expand Up @@ -669,7 +661,7 @@ class CUDT

int sndSpaceLeft()
{
return sndBuffersLeft() * maxPayloadSize();
return static_cast<int>(sndBuffersLeft() * maxPayloadSize());
}

int sndBuffersLeft()
Expand Down
14 changes: 7 additions & 7 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ void CUDTGroup::debugMasterData(SRTSOCKET slave)
// time when the connection process is done, until the first reading/writing happens.
ScopedLock cg(m_GroupLock);

SRTSOCKET mpeer;
steady_clock::time_point start_time;
IF_LOGGING(SRTSOCKET mpeer);
IF_LOGGING(steady_clock::time_point start_time);

bool found = false;

Expand All @@ -159,8 +159,8 @@ void CUDTGroup::debugMasterData(SRTSOCKET slave)
// Found it. Get the socket's peer's ID and this socket's
// Start Time. Once it's delivered, this can be used to calculate
// the Master-to-Slave start time difference.
mpeer = gi->ps->m_PeerID;
start_time = gi->ps->core().socketStartTime();
IF_LOGGING(mpeer = gi->ps->m_PeerID);
IF_LOGGING(start_time = gi->ps->core().socketStartTime());
HLOGC(gmlog.Debug,
log << "getMasterData: found RUNNING master @" << gi->id << " - reporting master's peer $" << mpeer
<< " starting at " << FormatTime(start_time));
Expand All @@ -185,8 +185,8 @@ void CUDTGroup::debugMasterData(SRTSOCKET slave)
// Found it. Get the socket's peer's ID and this socket's
// Start Time. Once it's delivered, this can be used to calculate
// the Master-to-Slave start time difference.
mpeer = gi->ps->core().m_PeerID;
start_time = gi->ps->core().socketStartTime();
IF_LOGGING(mpeer = gi->ps->core().m_PeerID);
IF_LOGGING(start_time = gi->ps->core().socketStartTime());
HLOGC(gmlog.Debug,
log << "getMasterData: found IDLE/PENDING master @" << gi->id << " - reporting master's peer $" << mpeer
<< " starting at " << FormatTime(start_time));
Expand All @@ -203,7 +203,7 @@ void CUDTGroup::debugMasterData(SRTSOCKET slave)
{
// The returned master_st is the master's start time. Calculate the
// differene time.
steady_clock::duration master_tdiff = m_tsStartTime - start_time;
IF_LOGGING(steady_clock::duration master_tdiff = m_tsStartTime - start_time);
LOGC(cnlog.Debug, log << CONID() << "FOUND GROUP MASTER LINK: peer=$" << mpeer
<< " - start time diff: " << FormatDuration<DUNIT_S>(master_tdiff));
}
Expand Down
3 changes: 3 additions & 0 deletions srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ written by
// Usage: LOGP(gglog.Debug, param1, param2, param3);
#define LOGP(logdes, ...) if (logdes.CheckEnabled()) logdes.printloc(__FILE__, __LINE__, __FUNCTION__,##__VA_ARGS__)

#define IF_LOGGING(instr) instr

#if ENABLE_HEAVY_LOGGING

#define HLOGC LOGC
Expand Down Expand Up @@ -95,6 +97,7 @@ written by
#define HLOGP(...)

#define IF_HEAVY_LOGGING(instr) (void)0
#define IF_LOGGING(instr) (void)0

#endif

Expand Down
6 changes: 3 additions & 3 deletions srtcore/socketconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class StringStorage

memcpy(stor, s, length);
stor[length] = 0;
len = length;
len = (int) length;
return true;
}

Expand Down Expand Up @@ -945,8 +945,8 @@ struct CSrtConfigSetter<SRTO_PAYLOADSIZE>
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}

size_t efc_max_payload_size = SRT_LIVE_MAX_PLSIZE - fc.extra_size;
if (val > efc_max_payload_size)
const size_t efc_max_payload_size = SRT_LIVE_MAX_PLSIZE - fc.extra_size;
if (size_t(val) > efc_max_payload_size)
{
LOGC(aclog.Error,
log << "SRTO_PAYLOADSIZE: value exceeds SRT_LIVE_MAX_PLSIZE decreased by " << fc.extra_size
Expand Down
2 changes: 1 addition & 1 deletion srtcore/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class CPktTimeWindow: CPktTimeWindowTools
m_tsCurrArrTime = srt::sync::steady_clock::now();

// record the packet interval between the current and the last one
m_aPktWindow[m_iPktWindowPtr] = srt::sync::count_microseconds(m_tsCurrArrTime - m_tsLastArrTime);
m_aPktWindow[m_iPktWindowPtr] = (int) srt::sync::count_microseconds(m_tsCurrArrTime - m_tsLastArrTime);
m_aBytesWindow[m_iPktWindowPtr] = pktsz;

// the window is logically circular
Expand Down

0 comments on commit 90c62af

Please sign in to comment.