mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-14 11:46:26 +00:00
Bind our UDP sockets to the same local address used by RTSP handshake
This means we can ensure a consistent local address for our outgoing PING traffic to keep the UDP flows alive without having to call connect() which breaks with multi-homed hosts on GFE and Sunshine v0.20 and earlier.
This commit is contained in:
@@ -9,7 +9,8 @@ static int terminationCallbackErrorCode;
|
||||
// Common globals
|
||||
char* RemoteAddrString;
|
||||
struct sockaddr_storage RemoteAddr;
|
||||
SOCKADDR_LEN RemoteAddrLen;
|
||||
struct sockaddr_storage LocalAddr;
|
||||
SOCKADDR_LEN AddrLen;
|
||||
int AppVersionQuad[4];
|
||||
STREAM_CONFIGURATION StreamConfig;
|
||||
CONNECTION_LISTENER_CALLBACKS ListenerCallbacks;
|
||||
@@ -254,6 +255,7 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
|
||||
memcpy(&ListenerCallbacks, clCallbacks, sizeof(ListenerCallbacks));
|
||||
ListenerCallbacks.connectionTerminated = ClInternalConnectionTerminated;
|
||||
|
||||
memset(&LocalAddr, 0, sizeof(LocalAddr));
|
||||
NegotiatedVideoFormat = 0;
|
||||
memcpy(&StreamConfig, streamConfig, sizeof(StreamConfig));
|
||||
OriginalVideoBitrate = streamConfig->bitrate;
|
||||
@@ -344,13 +346,13 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
|
||||
if (RtspPortNumber != 48010) {
|
||||
// If we have an alternate RTSP port, use that as our test port. The host probably
|
||||
// isn't listening on 47989 or 47984 anyway, since they're using alternate ports.
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, RtspPortNumber, &RemoteAddr, &RemoteAddrLen);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, RtspPortNumber, &RemoteAddr, &AddrLen);
|
||||
if (err != 0) {
|
||||
// Sleep for a second and try again. It's possible that we've attempt to connect
|
||||
// before the host has gotten around to listening on the RTSP port. Give it some
|
||||
// time before retrying.
|
||||
PltSleepMs(1000);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, RtspPortNumber, &RemoteAddr, &RemoteAddrLen);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, RtspPortNumber, &RemoteAddr, &AddrLen);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -360,12 +362,12 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
|
||||
// TCP 48010 is a last resort because:
|
||||
// a) it's not always listening and there's a race between listen() on the host and our connect()
|
||||
// b) it's not used at all by certain host versions which perform RTSP over ENet
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 47984, &RemoteAddr, &RemoteAddrLen);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 47984, &RemoteAddr, &AddrLen);
|
||||
if (err != 0) {
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 47989, &RemoteAddr, &RemoteAddrLen);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 47989, &RemoteAddr, &AddrLen);
|
||||
}
|
||||
if (err != 0) {
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 48010, &RemoteAddr, &RemoteAddrLen);
|
||||
err = resolveHostName(serverInfo->address, AF_UNSPEC, 48010, &RemoteAddr, &AddrLen);
|
||||
}
|
||||
}
|
||||
if (err != 0) {
|
||||
|
||||
Reference in New Issue
Block a user