TCPStreamPusher: Implement KEEPALIVE + writers stay connected

This commit is contained in:
2026-03-05 08:30:16 +01:00
parent cc33d5ff9c
commit 91591a3cc3
4 changed files with 327 additions and 76 deletions

View File

@@ -250,8 +250,32 @@ void TCPImagePuller::ReceiverThread() {
continue;
}
const auto frame_type = static_cast<TCPFrameType>(frame.header.type);
// Respond to keepalive ping with a keepalive pong
if (frame_type == TCPFrameType::KEEPALIVE) {
if (frame.header.payload_size > 0) {
std::vector<uint8_t> discard(frame.header.payload_size);
if (!ReadExact(discard.data(), discard.size())) {
CloseSocket();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
continue;
}
}
// Send keepalive pong back
TcpFrameHeader pong{};
pong.type = static_cast<uint16_t>(TCPFrameType::KEEPALIVE);
pong.payload_size = 0;
if (!SendAll(&pong, sizeof(pong))) {
logger.Info("Keepalive pong send failed, reconnecting to " + addr);
CloseSocket();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
continue;
}
// Ignore ACK on puller side
if (static_cast<TCPFrameType>(frame.header.type) == TCPFrameType::ACK) {
if (frame_type == TCPFrameType::ACK) {
if (frame.header.payload_size > 0) {
std::vector<uint8_t> discard(frame.header.payload_size);
if (!ReadExact(discard.data(), discard.size())) {