From 02951d41361270dfa394cf7f6a743480d5fd3250 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Mon, 21 Jul 2025 08:39:20 +0200 Subject: [PATCH] If an SVDRP peer connection is lost, the connection in the opposite direction is now also closed --- CONTRIBUTORS | 2 ++ HISTORY | 2 ++ svdrp.c | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b6c5c414..cfa61806 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2605,6 +2605,8 @@ Markus Ehrnsperger parameters of a previous call to cTimer::Matches() for fixing the stop time of repeating timers in case of DST change for suggesting to add cTimer::VpsTime() + for reporting that if an SVDRP peer connection is lost, the connection in the opposite + direction needs to be closed Werner Färber for reporting a bug in handling the cPluginManager::Active() result when pressing diff --git a/HISTORY b/HISTORY index 1c849cc2..f594c8fd 100644 --- a/HISTORY +++ b/HISTORY @@ -10170,3 +10170,5 @@ Video Disk Recorder Revision History Friedrichs). - Added cTimer::VpsTime() (suggested by Markus Ehrnsperger). - Now sending the SVDRP discover broadcast once per minute, to re-establish lost connections. +- If an SVDRP peer connection is lost, the connection in the opposite direction is now also + closed (reported by Markus Ehrnsperger). diff --git a/svdrp.c b/svdrp.c index 8f8fe7f1..b76c29b4 100644 --- a/svdrp.c +++ b/svdrp.c @@ -10,7 +10,7 @@ * and interact with the Video Disk Recorder - or write a full featured * graphical interface that sits on top of an SVDRP connection. * - * $Id: svdrp.c 5.12 2025/07/21 08:26:31 kls Exp $ + * $Id: svdrp.c 5.13 2025/07/21 08:39:20 kls Exp $ */ #include "svdrp.h" @@ -324,10 +324,10 @@ private: int fetchFlags; bool connected; bool Send(const char *Command); - void Close(void); public: cSVDRPClient(const char *Address, int Port, const char *ServerName, int Timeout); ~cSVDRPClient(); + void Close(void); const char *ServerName(void) const { return serverName; } const char *Connection(void) const { return serverIpAddress.Connection(); } bool HasAddress(const char *Address, int Port) const; @@ -465,6 +465,7 @@ bool cSVDRPClient::Process(cStringList *Response) } else if (Timeout.TimedOut()) { esyslog("SVDRP %s < %s timeout while waiting for response from '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName); + Close(); return false; } else if (!Response && numChars == 0) @@ -603,6 +604,7 @@ public: cSVDRPClientHandler(int TcpPort, int UdpPort); virtual ~cSVDRPClientHandler() override; void AddClient(cSVDRPServerParams &ServerParams, const char *IpAddress); + void CloseClient(const char *ServerName); bool Execute(const char *ServerName, const char *Command, cStringList *Response = NULL); bool GetServerNames(cStringList *ServerNames); bool TriggerFetchingTimers(const char *ServerName); @@ -696,6 +698,17 @@ void cSVDRPClientHandler::AddClient(cSVDRPServerParams &ServerParams, const char clientConnections.Append(new cSVDRPClient(IpAddress, ServerParams.Port(), ServerParams.Name(), ServerParams.Timeout())); } +void cSVDRPClientHandler::CloseClient(const char *ServerName) +{ + cMutexLock MutexLock(&mutex); + for (int i = 0; i < clientConnections.Size(); i++) { + if (strcmp(clientConnections[i]->ServerName(), ServerName) == 0) { + clientConnections[i]->Close(); + break; + } + } +} + void cSVDRPClientHandler::HandleClientConnection(void) { cString NewDiscover = udpSocket.Discover(); @@ -2784,6 +2797,8 @@ void cSVDRPServerHandler::ProcessConnections(void) { for (int i = 0; i < serverConnections.Size(); i++) { if (!serverConnections[i]->Process()) { + if (SVDRPClientHandler) + SVDRPClientHandler->CloseClient(serverConnections[i]->ClientName()); delete serverConnections[i]; serverConnections.Remove(i); i--;