Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/dvb/cahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,24 @@ void eDVBCAHandler::newConnection(int socket)
ePMTClient *client = new ePMTClient(this, client_fd);
clients.push_back(client);

/* Always distribute current CAPMTs first (legacy format, works for all clients) */
distributeCAPMT();

/* Send CLIENT_INFO only when appropriate:
* - Protocol-3 already established (OSCam reconnect): always send
* - First connection ever: send to probe for Protocol-3 support
* - Legacy client detected (no SERVER_INFO after first attempt): skip
* to avoid unnecessary errors in legacy softcam logs */
if (m_protocol3_established)
{
/* Protocol-3 reconnect: complete handshake first, distributeCAPMT()
* will be called from processServerInfoPacket() */
client->sendClientInfo();
}
else if (!m_handshake_attempted)
{
/* First connection: send legacy CAPMTs, then probe for Protocol-3 */
distributeCAPMT();
client->sendClientInfo();
m_handshake_attempted = true;
}
else
{
/* Legacy softcam - send CAPMTs immediately */
distributeCAPMT();
}
}

void eDVBCAHandler::connectionLost(ePMTClient *client)
Expand Down
69 changes: 43 additions & 26 deletions lib/dvb/cwhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void eDVBCWHandler::threadLoop()
const Connection& conn = conns_snapshot[i];

// Softcam → proxy_fd (and intercept CWs)
bool softcam_disconnected = false;
if (pfds[softcam_idx].revents & POLLIN)
{
ssize_t n = ::read(conn.softcam_fd, buf, sizeof(buf));
Expand All @@ -283,31 +284,40 @@ void eDVBCWHandler::threadLoop()
written += w;
}
}
else if (n == 0)
{
// EOF - softcam closed the connection
eDebug("[eDVBCWHandler] Softcam EOF on fd %d", conn.softcam_fd);
softcam_disconnected = true;
}
else if (errno != EINTR && errno != EAGAIN)
{
eDebug("[eDVBCWHandler] Softcam read error on fd %d: %m", conn.softcam_fd);
softcam_disconnected = true;
}
}

// Handle softcam disconnect
if (pfds[softcam_idx].revents & (POLLHUP | POLLERR))
if (softcam_disconnected || (pfds[softcam_idx].revents & (POLLHUP | POLLERR)))
{
if (!(pfds[softcam_idx].revents & POLLIN)) // Only if no data pending
eDebug("[eDVBCWHandler] Softcam disconnected on fd %d", conn.softcam_fd);
// Close proxy_fd so ePMTClient gets connectionLost
std::lock_guard<std::mutex> lock(m_connections_mutex);
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
{
eDebug("[eDVBCWHandler] Softcam disconnected on fd %d", conn.softcam_fd);
// Close proxy_fd so ePMTClient gets connectionLost
std::lock_guard<std::mutex> lock(m_connections_mutex);
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
if (it->softcam_fd == conn.softcam_fd)
{
if (it->softcam_fd == conn.softcam_fd)
{
::close(it->softcam_fd);
::close(it->proxy_fd);
m_connections.erase(it);
break;
}
::close(it->softcam_fd);
::close(it->proxy_fd);
m_connections.erase(it);
break;
}
continue;
}
continue;
}

// proxy_fd → softcam (CAPMT writes from ePMTClient)
bool proxy_disconnected = false;
if (pfds[proxy_idx].revents & POLLIN)
{
ssize_t n = ::read(conn.proxy_fd, buf, sizeof(buf));
Expand All @@ -330,24 +340,31 @@ void eDVBCWHandler::threadLoop()
written += w;
}
}
else if (n == 0)
{
eDebug("[eDVBCWHandler] ePMTClient EOF on proxy_fd %d", conn.proxy_fd);
proxy_disconnected = true;
}
else if (errno != EINTR && errno != EAGAIN)
{
eDebug("[eDVBCWHandler] ePMTClient read error on proxy_fd %d: %m", conn.proxy_fd);
proxy_disconnected = true;
}
}

// Handle ePMTClient disconnect
if (pfds[proxy_idx].revents & (POLLHUP | POLLERR))
if (proxy_disconnected || (pfds[proxy_idx].revents & (POLLHUP | POLLERR)))
{
if (!(pfds[proxy_idx].revents & POLLIN))
eDebug("[eDVBCWHandler] ePMTClient disconnected on proxy_fd %d", conn.proxy_fd);
std::lock_guard<std::mutex> lock(m_connections_mutex);
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
{
eDebug("[eDVBCWHandler] ePMTClient disconnected on proxy_fd %d", conn.proxy_fd);
std::lock_guard<std::mutex> lock(m_connections_mutex);
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
if (it->proxy_fd == conn.proxy_fd)
{
if (it->proxy_fd == conn.proxy_fd)
{
::close(it->softcam_fd);
::close(it->proxy_fd);
m_connections.erase(it);
break;
}
::close(it->softcam_fd);
::close(it->proxy_fd);
m_connections.erase(it);
break;
}
}
}
Expand Down
Loading