Skip to content

Commit 3d76eee

Browse files
committed
impr: handling TCP read timeout and error
1 parent 87402b9 commit 3d76eee

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tcp_client.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,26 @@ class BridgeTCPClient : public Client {
193193
}
194194

195195
MsgPack::arr_t<uint8_t> message;
196-
RpcCall async_rpc = bridge->call(TCP_READ_METHOD, connection_id, size, read_timeout);
197-
const bool ret = async_rpc.result(message);
196+
bool ret;
197+
int err;
198+
199+
if (read_timeout > 0) {
200+
RpcCall async_rpc_timeout = bridge->call(TCP_READ_METHOD, connection_id, size, read_timeout);
201+
ret = async_rpc_timeout.result(message);
202+
err = async_rpc_timeout.getErrorCode();
203+
} else {
204+
RpcCall async_rpc = bridge->call(TCP_READ_METHOD, connection_id, size);
205+
ret = async_rpc.result(message);
206+
err = async_rpc.getErrorCode();
207+
}
198208

199209
if (ret) {
200210
for (size_t i = 0; i < message.size(); ++i) {
201211
temp_buffer.store_char(static_cast<char>(message[i]));
202212
}
203213
}
204214

205-
if (async_rpc.getErrorCode() > NO_ERR) {
215+
if (err > NO_ERR) {
206216
_connected = false;
207217
}
208218

0 commit comments

Comments
 (0)