[client] spice: gate USB reconnect on MAIN health

This commit is contained in:
Geoffrey McRae
2026-08-16 22:01:59 +10:00
parent d26e73f615
commit 209ac4d749
2 changed files with 30 additions and 1 deletions

View File

@@ -55,6 +55,8 @@ struct LG_USBRedir
bool disconnectPending;
int64_t disconnectDeadline;
int64_t reconnectDeadline;
uint64_t mainPingCount;
bool waitingForMainPing;
};
static void setAvailable(LG_USBRedir * usbredir, bool available)
@@ -192,6 +194,25 @@ static bool selectChannel(LG_USBRedir * usbredir)
if (usbredir->channel)
return true;
if (!purespice_channelConnected(PS_CHANNEL_MAIN))
{
usbredir->reconnectDeadline =
(int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS;
return false;
}
if (usbredir->waitingForMainPing)
{
if (purespice_mainPingCount() == usbredir->mainPingCount)
{
usbredir->reconnectDeadline =
(int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS;
return false;
}
usbredir->waitingForMainPing = false;
}
for (unsigned int i = 0; i < USB_REDIR_CHANNEL_COUNT; ++i)
{
PSUSBRedirChannel * channel = usbredir->channels[i];
@@ -424,9 +445,17 @@ void lgUsbRedir_state(PSUSBRedirChannel * channel,
destroyParser(usbredir);
usbredir->channel = NULL;
if (purespice_usbRedirAvailable(channel))
{
/* Wait for a fresh MAIN PING/PONG before reconnecting this
* optional channel. The server shuts it down before MAIN during a
* session teardown, so this prevents reconnect attempts to a
* disappearing SPICE server. */
usbredir->mainPingCount = purespice_mainPingCount();
usbredir->waitingForMainPing = true;
usbredir->reconnectDeadline =
(int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS;
}
}
break;
case PS_USB_REDIR_UNAVAILABLE: