obs-outputs: Improve librtmp timeouts on Linux

Replaces the usage of SO_SNDTIMEO with TCP_USER_TIMEOUT on Linux.
- Noted as more effective than SO_SNDTIMEO by multiple sources.
- Drops TCP connection on timeout instead of returning send() errors,
meaning more predictable reconnect timing and reconnect.
- Timeout period actually reflected in practice. SO_SNDTIMEO takes
double the timeout time than actually requested to time out on
unix, whereas WinSock actually waits the specified time.
master
tt2468 2022-05-07 00:34:22 -07:00
parent 6c7f8853a8
commit 70f33f7794
1 changed files with 14 additions and 4 deletions

View File

@ -85,7 +85,16 @@ static const char *my_dhm_G = "4";
#include <openssl/bio.h>
#include <openssl/buffer.h>
#endif
#endif
#if defined(TCP_USER_TIMEOUT)
#define SOCKET_LEVEL IPPROTO_TCP
#define SOCKET_TIMEOUT_OPT TCP_USER_TIMEOUT
#define SOCKET_TIMEOUT_VAR(tv, s) int tv = s*1000
#else
#define SOCKET_LEVEL SOL_SOCKET
#define SOCKET_TIMEOUT_OPT SO_SNDTIMEO
#define SOCKET_TIMEOUT_VAR(tv, s) SET_RCVTIMEO(tv, s)
#endif
#define RTMP_SIG_SIZE 1536
@ -931,13 +940,14 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service, socklen_t addrlen)
__FUNCTION__, r->Link.receiveTimeout);
}
SET_RCVTIMEO(tvs, r->Link.sendTimeout);
if (setsockopt
(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&tvs, sizeof(tvs)))
#if defined(SOCKET_TIMEOUT_OPT)
SOCKET_TIMEOUT_VAR(to, r->Link.sendTimeout);
if (setsockopt(r->m_sb.sb_socket, SOCKET_LEVEL, SOCKET_TIMEOUT_OPT, &to, sizeof(to)))
{
RTMP_Log(RTMP_LOGERROR, "%s, Setting socket send timeout to %ds failed!",
RTMP_Log(RTMP_LOGERROR, "%s, Setting socket SOCKET_TIMEOUT_OPT to %ds failed!",
__FUNCTION__, r->Link.sendTimeout);
}
#endif
}
if(!r->m_bUseNagle)