Check debug port connection 40/281740/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 21 Sep 2022 08:20:13 +0000 (08:20 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 21 Sep 2022 08:21:05 +0000 (08:21 +0000)
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 <h.jhun@samsung.com>
src/rpc-port.cc

index 1ccd5e5..6d38540 100644 (file)
@@ -229,19 +229,23 @@ RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) {
 
   auto port = static_cast<Port*>(h);
   uint32_t seq = 0;
-  int ret = port->Read(reinterpret_cast<uint32_t*>(&seq), sizeof(seq));
-  if (ret < 0) {
-    _E("IO Error");
-    return ret;
+  if (DebugPort::IsConnected()) {
+    int ret = port->Read(reinterpret_cast<uint32_t*>(&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<Port*>(h);
   uint32_t seq = port->GetSeq();
-  int ret = port->Write(reinterpret_cast<void*>(&seq), sizeof(seq));
-  if (ret < 0)
-    return ret;
+  if (DebugPort::IsConnected()) {
+    int ret = port->Write(reinterpret_cast<void*>(&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;
 }