From a49371e1f9f157392f3c74b147f332d43a5b0ed3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 21 Sep 2022 08:20:13 +0000 Subject: [PATCH] Check debug port connection If the debug port is not connected, the rpc-port doesn't send and receive the sequence number. Change-Id: I7697410a0500a790fad2328d9aa4ff54a93da652 Signed-off-by: Hwankyu Jhun --- src/rpc-port.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 1ccd5e5..6d38540 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -229,19 +229,23 @@ RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) { auto port = static_cast(h); uint32_t seq = 0; - int ret = port->Read(reinterpret_cast(&seq), sizeof(seq)); - if (ret < 0) { - _E("IO Error"); - return ret; + if (DebugPort::IsConnected()) { + int ret = port->Read(reinterpret_cast(&seq), sizeof(seq)); + if (ret < 0) { + _E("IO Error"); + return ret; + } } - ret = port->Read(buf, size); + int ret = port->Read(buf, size); if (ret < 0) { _E("IO Error"); return ret; } - DebugPort::Send(port->GetFd(), true, seq, buf, size); + if (DebugPort::IsConnected()) + DebugPort::Send(port->GetFd(), true, seq, buf, size); + return RPC_PORT_ERROR_NONE; } @@ -251,15 +255,19 @@ RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) { auto port = static_cast(h); uint32_t seq = port->GetSeq(); - int ret = port->Write(reinterpret_cast(&seq), sizeof(seq)); - if (ret < 0) - return ret; + if (DebugPort::IsConnected()) { + int ret = port->Write(reinterpret_cast(&seq), sizeof(seq)); + if (ret < 0) + return ret; + } - ret = port->Write(buf, size); + int ret = port->Write(buf, size); if (ret < 0) return ret; - DebugPort::Send(port->GetFd(), false, seq, buf, size); + if (DebugPort::IsConnected()) + DebugPort::Send(port->GetFd(), false, seq, buf, size); + return RPC_PORT_ERROR_NONE; } -- 2.7.4