Skip to content

Commit e5a1179

Browse files
authored
[core] Fix UDP RCVBUF and SNDBUF on Solaris (#2162).
Check system maximum is not exceeded.
1 parent 6ae42c6 commit e5a1179

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

srtcore/channel.cpp

+75-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,81 @@ void srt::CChannel::attach(UDPSOCKET udpsock, const sockaddr_any& udpsocks_addr)
265265

266266
void srt::CChannel::setUDPSockOpt()
267267
{
268-
#if defined(BSD) || TARGET_OS_MAC
268+
#if defined(SUNOS)
269+
{
270+
socklen_t optSize;
271+
// Retrieve starting SND/RCV Buffer sizes.
272+
int startRCVBUF = 0;
273+
optSize = sizeof(startRCVBUF);
274+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_RCVBUF, (void*)&startRCVBUF, &optSize))
275+
{
276+
startRCVBUF = -1;
277+
}
278+
int startSNDBUF = 0;
279+
optSize = sizeof(startSNDBUF);
280+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_SNDBUF, (void*)&startSNDBUF, &optSize))
281+
{
282+
startSNDBUF = -1;
283+
}
284+
285+
// SunOS will fail setsockopt() if the requested buffer size exceeds system
286+
// maximum value.
287+
// However, do not reduce the buffer size.
288+
const int maxsize = 64000;
289+
if (0 !=
290+
::setsockopt(
291+
m_iSocket, SOL_SOCKET, SO_RCVBUF, (const char*)&m_mcfg.iUDPRcvBufSize, sizeof m_mcfg.iUDPRcvBufSize))
292+
{
293+
int currentRCVBUF = 0;
294+
optSize = sizeof(currentRCVBUF);
295+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_RCVBUF, (void*)&currentRCVBUF, &optSize))
296+
{
297+
currentRCVBUF = -1;
298+
}
299+
if (maxsize > currentRCVBUF)
300+
{
301+
::setsockopt(m_iSocket, SOL_SOCKET, SO_RCVBUF, (const char*)&maxsize, sizeof maxsize);
302+
}
303+
}
304+
if (0 !=
305+
::setsockopt(
306+
m_iSocket, SOL_SOCKET, SO_SNDBUF, (const char*)&m_mcfg.iUDPSndBufSize, sizeof m_mcfg.iUDPSndBufSize))
307+
{
308+
int currentSNDBUF = 0;
309+
optSize = sizeof(currentSNDBUF);
310+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_RCVBUF, (void*)&currentSNDBUF, &optSize))
311+
{
312+
currentSNDBUF = -1;
313+
}
314+
if (maxsize > currentSNDBUF)
315+
{
316+
::setsockopt(m_iSocket, SOL_SOCKET, SO_SNDBUF, (const char*)&maxsize, sizeof maxsize);
317+
}
318+
}
319+
320+
// Retrieve ending SND/RCV Buffer sizes.
321+
int endRCVBUF = 0;
322+
optSize = sizeof(endRCVBUF);
323+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_RCVBUF, (void*)&endRCVBUF, &optSize))
324+
{
325+
endRCVBUF = -1;
326+
}
327+
int endSNDBUF = 0;
328+
optSize = sizeof(endSNDBUF);
329+
if (0 != ::getsockopt(m_iSocket, SOL_SOCKET, SO_SNDBUF, (void*)&endSNDBUF, &optSize))
330+
{
331+
endSNDBUF = -1;
332+
}
333+
LOGC(kmlog.Debug,
334+
log << "SO_RCVBUF:"
335+
<< " startRCVBUF=" << startRCVBUF << " m_mcfg.iUDPRcvBufSize=" << m_mcfg.iUDPRcvBufSize
336+
<< " endRCVBUF=" << endRCVBUF);
337+
LOGC(kmlog.Debug,
338+
log << "SO_SNDBUF:"
339+
<< " startSNDBUF=" << startSNDBUF << " m_mcfg.iUDPSndBufSize=" << m_mcfg.iUDPSndBufSize
340+
<< " endSNDBUF=" << endSNDBUF);
341+
}
342+
#elif defined(BSD) || TARGET_OS_MAC
269343
// BSD system will fail setsockopt if the requested buffer size exceeds system maximum value
270344
int maxsize = 64000;
271345
if (0 != ::setsockopt(

0 commit comments

Comments
 (0)