mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-02-16 02:21:07 +00:00
Improve ENet socket error propagation for better debuggability
This commit is contained in:
@@ -1068,6 +1068,10 @@ static void controlReceiveThreadFunc(void* context) {
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
// The error from serviceEnetHost() should be propagated via LastSocketError()
|
||||
LC_ASSERT(err == -1);
|
||||
|
||||
err = LastSocketFail();
|
||||
Limelog("Control stream connection failed: %d\n", err);
|
||||
ListenerCallbacks.connectionTerminated(err);
|
||||
return;
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
static int serviceEnetHostInternal(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs, bool ignoreInterrupts) {
|
||||
int ret;
|
||||
|
||||
// Clear the last socket error to ensure the caller doesn't read a stale error upon a
|
||||
// failure in non-socket-related processing in enet_host_service()
|
||||
SetLastSocketError(0);
|
||||
|
||||
// We need to call enet_host_service() multiple times to make sure retransmissions happen
|
||||
for (;;) {
|
||||
int selectedTimeout = timeoutMs < ENET_INTERNAL_TIMEOUT_MS ? timeoutMs : ENET_INTERNAL_TIMEOUT_MS;
|
||||
@@ -16,6 +20,7 @@ static int serviceEnetHostInternal(ENetHost* client, ENetEvent* event, enet_uint
|
||||
// We want to report an interrupt event if we are able to read data
|
||||
if (!ignoreInterrupts && ConnectionInterrupted) {
|
||||
Limelog("ENet wait interrupted\n");
|
||||
SetLastSocketError(EINTR);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -67,7 +72,7 @@ int gracefullyDisconnectEnetPeer(ENetHost* host, ENetPeer* peer, enet_uint32 lin
|
||||
Limelog("Timed out waiting for ENet peer to acknowledge disconnection\n");
|
||||
}
|
||||
else {
|
||||
Limelog("Failed to receive ENet peer disconnection acknowledgement\n");
|
||||
Limelog("Failed to receive ENet peer disconnection acknowledgement: %d\n", LastSocketFail());
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -144,7 +144,7 @@ static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE respons
|
||||
// Wait for a reply
|
||||
if (serviceEnetHost(client, &event, RTSP_RECEIVE_TIMEOUT_SEC * 1000) <= 0 ||
|
||||
event.type != ENET_EVENT_TYPE_RECEIVE) {
|
||||
Limelog("Failed to receive RTSP reply\n");
|
||||
Limelog("Failed to receive RTSP reply: %d\n", LastSocketFail());
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE respons
|
||||
// The payload comes in a second packet
|
||||
if (serviceEnetHost(client, &event, RTSP_RECEIVE_TIMEOUT_SEC * 1000) <= 0 ||
|
||||
event.type != ENET_EVENT_TYPE_RECEIVE) {
|
||||
Limelog("Failed to receive RTSP reply payload\n");
|
||||
Limelog("Failed to receive RTSP reply payload: %d\n", LastSocketFail());
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
@@ -851,7 +851,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
|
||||
// Wait for the connect to complete
|
||||
if (serviceEnetHost(client, &event, RTSP_CONNECT_TIMEOUT_SEC * 1000) <= 0 ||
|
||||
event.type != ENET_EVENT_TYPE_CONNECT) {
|
||||
Limelog("RTSP: Failed to connect to UDP port %u\n", RtspPortNumber);
|
||||
Limelog("RTSP: Failed to connect to UDP port %u: error %d\n", RtspPortNumber, LastSocketFail());
|
||||
enet_peer_reset(peer);
|
||||
peer = NULL;
|
||||
enet_host_destroy(client);
|
||||
|
||||
Reference in New Issue
Block a user