mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-17 17:05:50 +00:00
Enable SO_RCVTIMEO for RTP sockets on Windows
This commit is contained in:
parent
d9ea208dea
commit
122ce4a568
@ -56,10 +56,14 @@ void shutdownTcpSocket(SOCKET s) {
|
|||||||
|
|
||||||
int setNonFatalRecvTimeoutMs(SOCKET s, int timeoutMs) {
|
int setNonFatalRecvTimeoutMs(SOCKET s, int timeoutMs) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
// Windows says that SO_RCVTIMEO puts the socket
|
// Windows says that SO_RCVTIMEO puts the socket into an indeterminate state
|
||||||
// into an indeterminate state, so we won't use
|
// when a timeout occurs. MSDN doesn't go into it any more than that, but it
|
||||||
// it for non-fatal socket operations.
|
// seems likely that they are referring to the inability to know whether a
|
||||||
return -1;
|
// cancelled request consumed some data or not (very relevant for stream-based
|
||||||
|
// protocols like TCP). Since our sockets are UDP which is already unreliable,
|
||||||
|
// losing some data in a very rare case is fine, especially because we get to
|
||||||
|
// halve the number of syscalls per packet by avoiding select().
|
||||||
|
return setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeoutMs, sizeof(timeoutMs));
|
||||||
#else
|
#else
|
||||||
struct timeval val;
|
struct timeval val;
|
||||||
|
|
||||||
@ -195,7 +199,8 @@ int recvUdpSocket(SOCKET s, char* buffer, int size, bool useSelect) {
|
|||||||
if (err < 0 &&
|
if (err < 0 &&
|
||||||
(LastSocketError() == EWOULDBLOCK ||
|
(LastSocketError() == EWOULDBLOCK ||
|
||||||
LastSocketError() == EINTR ||
|
LastSocketError() == EINTR ||
|
||||||
LastSocketError() == EAGAIN)) {
|
LastSocketError() == EAGAIN ||
|
||||||
|
LastSocketError() == ETIMEDOUT)) {
|
||||||
// Return 0 for timeout
|
// Return 0 for timeout
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user