Disconnect from a port 45/249645/4
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Dec 2020 00:56:05 +0000 (09:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 24 Dec 2020 03:25:58 +0000 (12:25 +0900)
After this patch is applied, rpc-port closes the file descriptor when
Read() is failed.

Change-Id: I25c1a2878037a664c4bec8320f97bc1fafeef38b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/port-internal.cc
src/port-internal.hh
src/rpc-port.cc

index ec798fd..0b61a27 100644 (file)
@@ -78,7 +78,15 @@ Port::Port(int fd, std::string id, std::string instance)
 
 Port::~Port() {
   ClearQueue();
-  close(fd_);
+  Disconnect();
+}
+
+void Port::Disconnect() {
+  if (fd_ > 0) {
+    _W("Close fd(%d)", fd_);
+    close(fd_);
+    fd_ = -1;
+  }
 }
 
 int Port::SetPrivateSharing(const char* paths[], unsigned int size) {
index a8cd03a..96c31a5 100644 (file)
@@ -36,6 +36,7 @@ class Port {
   Port(int fd, std::string id);
   virtual ~Port();
 
+  void Disconnect();
   int SetPrivateSharing(const char* paths[], unsigned int size);
   int SetPrivateSharing(const char* path);
   int UnsetPrivateSharing();
index 451fb83..04e20c8 100644 (file)
@@ -207,12 +207,18 @@ 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)
+  if (ret < 0) {
+    _E("IO Error");
+    port->Disconnect();
     return ret;
+  }
 
   ret = port->Read(buf, size);
-  if (ret < 0)
+  if (ret < 0) {
+    _E("IO Error");
+    port->Disconnect();
     return ret;
+  }
 
   auto& debug_port = DebugPort::GetInst();
   debug_port.Send(port->GetFd(), true, seq, buf, size);