TCPStreamPusher: Implement KEEPALIVE + writers stay connected
This commit is contained in:
@@ -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())) {
|
||||
|
||||
Reference in New Issue
Block a user