From 3d76eeee2473362f619421164efe3ff9815ca119 Mon Sep 17 00:00:00 2001 From: Lucio Rossi Date: Mon, 1 Dec 2025 18:07:23 +0100 Subject: [PATCH] impr: handling TCP read timeout and error --- src/tcp_client.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tcp_client.h b/src/tcp_client.h index 39c851d..0bc8391 100644 --- a/src/tcp_client.h +++ b/src/tcp_client.h @@ -193,8 +193,18 @@ class BridgeTCPClient : public Client { } MsgPack::arr_t message; - RpcCall async_rpc = bridge->call(TCP_READ_METHOD, connection_id, size, read_timeout); - const bool ret = async_rpc.result(message); + bool ret; + int err; + + if (read_timeout > 0) { + RpcCall async_rpc_timeout = bridge->call(TCP_READ_METHOD, connection_id, size, read_timeout); + ret = async_rpc_timeout.result(message); + err = async_rpc_timeout.getErrorCode(); + } else { + RpcCall async_rpc = bridge->call(TCP_READ_METHOD, connection_id, size); + ret = async_rpc.result(message); + err = async_rpc.getErrorCode(); + } if (ret) { for (size_t i = 0; i < message.size(); ++i) { @@ -202,7 +212,7 @@ class BridgeTCPClient : public Client { } } - if (async_rpc.getErrorCode() > NO_ERR) { + if (err > NO_ERR) { _connected = false; }