pkarashchenko commented on code in PR #6671:
URL: https://github.com/apache/incubator-nuttx/pull/6671#discussion_r926944016


##########
fs/rpmsgfs/rpmsgfs_client.c:
##########
@@ -434,38 +440,70 @@ int rpmsgfs_client_close(FAR void *handle, int fd)
 ssize_t rpmsgfs_client_read(FAR void *handle, int fd,
                             FAR void *buf, size_t count)
 {
-  size_t read = 0;
+  FAR struct rpmsgfs_s *priv = handle;
+  struct iovec read =
+    {
+      .iov_base = buf,
+      .iov_len  = 0,

Review Comment:
   Minor
   ```suggestion
   ```
   



##########
fs/rpmsgfs/rpmsgfs_client.c:
##########
@@ -434,38 +440,70 @@ int rpmsgfs_client_close(FAR void *handle, int fd)
 ssize_t rpmsgfs_client_read(FAR void *handle, int fd,
                             FAR void *buf, size_t count)
 {
-  size_t read = 0;
+  FAR struct rpmsgfs_s *priv = handle;
+  struct iovec read =
+    {
+      .iov_base = buf,
+      .iov_len  = 0,
+    };
+
+  struct rpmsgfs_cookie_s cookie;
+  struct rpmsgfs_read_s msg;
   int ret = 0;
 
-  while (read < count)
+  if (!buf || count <= 0)
     {
-      struct rpmsgfs_read_s msg =
-      {
-        .fd    = fd,
-        .count = count - read,
-      };
+      return 0;
+    }
 
-      ret = rpmsgfs_send_recv(handle, RPMSGFS_READ, true,
-              (FAR struct rpmsgfs_header_s *)&msg, sizeof(msg), buf);
-      if (ret <= 0)
-        {
-          break;
-        }
+  memset(&cookie, 0, sizeof(cookie));
 
-      read += ret;
-      buf  += ret;
+  nxsem_init(&cookie.sem, 0, 0);
+  nxsem_set_protocol(&cookie.sem, SEM_PRIO_NONE);
+  cookie.data = &read;
+
+  msg.header.command = RPMSGFS_READ;
+  msg.header.result  = -ENXIO;
+  msg.header.cookie  = (uintptr_t)&cookie;
+  msg.fd             = fd;
+  msg.count          = count;
+
+  ret = rpmsg_send(&priv->ept, &msg, sizeof(msg));
+  if (ret < 0)
+    {
+      goto out;
     }
 
-  return read ? read : ret;
+  ret = rpmsg_wait(&priv->ept, &cookie.sem);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  ret = cookie.result;
+
+out:
+  nxsem_destroy(&cookie.sem);
+  return read.iov_len ? read.iov_len : ret;

Review Comment:
   ```suggestion
     return read.iov_len > 0 ? read.iov_len : ret;
   ```
   



##########
fs/rpmsgfs/rpmsgfs_server.c:
##########
@@ -370,30 +370,44 @@ static int rpmsgfs_read_handler(FAR struct rpmsg_endpoint 
*ept,
   FAR struct rpmsgfs_read_s *rsp;
   FAR struct file *filep;
   int ret = -ENOENT;
+  size_t read = 0;
   uint32_t space;
 
-  rsp = rpmsg_get_tx_payload_buffer(ept, &space, true);
-  if (!rsp)
+  filep = rpmsgfs_get_file(priv, msg->fd);
+
+  while (read < msg->count)
     {
-      return -ENOMEM;
-    }
+      rsp = rpmsg_get_tx_payload_buffer(ept, &space, true);
+      if (!rsp)

Review Comment:
   Optional
   ```suggestion
         if (rsp == NULL)
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to