diff --git a/src/ControlStream.c b/src/ControlStream.c index 61e0842..0f8957f 100644 --- a/src/ControlStream.c +++ b/src/ControlStream.c @@ -466,8 +466,6 @@ static void controlReceiveThreadFunc(void* context) { return; } - int terminationErrorCode = -1; - while (!PltIsThreadInterrupted(&controlReceiveThread)) { ENetEvent event; @@ -501,7 +499,7 @@ static void controlReceiveThreadFunc(void* context) { // assume the server died tragically, so go ahead and tear down. PltUnlockMutex(&enetMutex); Limelog("Disconnect event timeout expired\n"); - ListenerCallbacks.connectionTerminated(terminationErrorCode); + ListenerCallbacks.connectionTerminated(-1); return; } } @@ -557,6 +555,7 @@ static void controlReceiveThreadFunc(void* context) { BbInitializeWrappedBuffer(&bb, (char*)event.packet->data, sizeof(*ctlHdr), event.packet->dataLength - sizeof(*ctlHdr), BYTE_ORDER_LITTLE); unsigned short terminationReason; + int terminationErrorCode; BbGetShort(&bb, (short*)&terminationReason); @@ -572,15 +571,21 @@ static void controlReceiveThreadFunc(void* context) { terminationErrorCode = terminationReason; } - // We don't actually notify the connection listener until we receive - // the disconnect event from the server that confirms the termination. + // We used to wait for a ENET_EVENT_TYPE_DISCONNECT event, but since + // GFE 3.20.3.63 we don't get one for 10 seconds after we first get + // this termination message. The termination message should be reliable + // enough to end the stream now, rather than waiting for an explicit + // disconnect. + ListenerCallbacks.connectionTerminated(terminationErrorCode); + enet_packet_destroy(event.packet); + return; } enet_packet_destroy(event.packet); } else if (event.type == ENET_EVENT_TYPE_DISCONNECT) { - Limelog("Control stream received disconnect event\n"); - ListenerCallbacks.connectionTerminated(terminationErrorCode); + Limelog("Control stream received unexpected disconnect event\n"); + ListenerCallbacks.connectionTerminated(-1); return; } }