Modify Port::Write() method
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 18 Jan 2023 06:20:02 +0000 (06:20 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 18 Jan 2023 06:44:24 +0000 (06:44 +0000)
After this patch is applied, if the cache buffer is not empty, the
rpc-port library checks the socket whether writing is possible or not.
If it's possible, the rpc-port library writes the delayed message to
the socket fd.

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

index b895d88..a937278 100644 (file)
@@ -223,19 +223,7 @@ int Port::Write(const void* buf, unsigned int size) {
       return RPC_PORT_ERROR_NONE;
     else if (ret == PORT_STATUS_ERROR_IO_ERROR)
       return RPC_PORT_ERROR_IO_ERROR;
-  }
-
-  if (delayed_message_size_ > QUEUE_SIZE_MAX) {
-    _E("cache fail : delayed_message_size (%d), count(%zu)",
-                            delayed_message_size_, queue_.size());
-    return RPC_PORT_ERROR_IO_ERROR;
-  }
-
-  ret = PushDelayedMessage(
-          std::make_shared<DelayMessage>(static_cast<const char*>(buf),
-          sent_bytes, size));
-
-  if (CanWrite()) {
+  } else if (CanWrite()) {
     while (!queue_.empty()) {
       int port_status = PopDelayedMessage();
       if (port_status != PORT_STATUS_ERROR_NONE) {
@@ -247,7 +235,15 @@ int Port::Write(const void* buf, unsigned int size) {
     }
   }
 
-  return ret;
+  if (delayed_message_size_ > QUEUE_SIZE_MAX) {
+    _E("cache fail : delayed_message_size (%d), count(%zu)",
+        delayed_message_size_, queue_.size());
+    return RPC_PORT_ERROR_IO_ERROR;
+  }
+
+  return PushDelayedMessage(
+      std::make_shared<DelayMessage>(
+        static_cast<const char*>(buf), sent_bytes, size));
 }
 
 int Port::Write(const void* buf, unsigned int size, int* sent_bytes) {
@@ -299,6 +295,8 @@ gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition,
     return G_SOURCE_REMOVE;
   }
 
+  _W("Writing is now possible. fd: %d, id: %s",
+      port->GetFd(), port->GetId().c_str());
   std::lock_guard<std::recursive_mutex> lock(port->rw_mutex_);
   if (port->source_id_ == 0) {
     _E("GSource is destroyed");