From: Lars Op den Kamp Date: Thu, 2 Feb 2012 00:02:56 +0000 (+0100) Subject: cec: close and delete the connection when the processor thread ends. fixes reconnect... X-Git-Tag: upstream/2.2.0~1^2~36^2~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9f9c8c82288f9754d8d375c2e1dc0bf44292f290;p=deb_libcec.git cec: close and delete the connection when the processor thread ends. fixes reconnect after standby (access denied / connection already opened) --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7041b78..38c9b76 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -134,8 +134,9 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint CLockObject lock(m_mutex); if (m_communication) { - CLibCEC::AddLog(CEC_LOG_ERROR, "existing connection handler found"); - return bReturn; + CLibCEC::AddLog(CEC_LOG_WARNING, "existing connection handler found, deleting it"); + m_communication->Close(); + delete m_communication; } m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); @@ -449,7 +450,11 @@ void *CCECProcessor::Process(void) } if (m_communication) + { m_communication->Close(); + delete m_communication; + m_communication = NULL; + } return NULL; } diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index e2b0386..a3b7c45 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -55,12 +55,6 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(CCECProcessor *processo CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void) { Close(); - - if (m_port) - { - delete m_port; - m_port = NULL; - } } bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */) @@ -143,6 +137,12 @@ void *CUSBCECAdapterCommunication::Process(void) if (m_outBuffer.Pop(msg)) msg->condition.Broadcast(); + if (m_port) + { + delete m_port; + m_port = NULL; + } + return NULL; }