xiaoxiang781216 commented on code in PR #20702:
URL: https://github.com/apache/nuttx/pull/20702#discussion_r4439452178


##########
mm/iob/iob_copyin.c:
##########
@@ -245,3 +247,91 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t 
*src,
 {
   return iob_copyin_internal(iob, src, len, offset, throttled, false);
 }
+
+/****************************************************************************
+ * Name: iob_copyin_iov_internal
+ *
+ * Description:
+ *  Iterate through an array of 'iov' buffers and copy each into the I/O
+ *  buffer chain, updating the offset for each segment.
+ *
+ ****************************************************************************/
+
+static int iob_copyin_iov_internal(FAR struct iob_s *iob,
+                                   FAR const struct iovec *iov,
+                                   unsigned int iovlen, int offset,
+                                   bool throttled, bool block)
+{
+  int total_copied = 0;
+  int ret;
+  unsigned int i;
+
+  if (iob == NULL || iov == NULL || iovlen == 0)
+    {
+      return 0;
+    }
+
+  for (i = 0; i < iovlen; i++)
+    {
+      if (iov[i].iov_len == 0)
+        {
+          continue;
+        }
+
+      if (iov[i].iov_base == NULL)
+        {
+          return -EINVAL;
+        }
+
+      if (iov[i].iov_len > (size_t)(INT_MAX - total_copied) ||

Review Comment:
   remove the cast



##########
mm/iob/iob_copyin.c:
##########
@@ -245,3 +247,91 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t 
*src,
 {
   return iob_copyin_internal(iob, src, len, offset, throttled, false);
 }
+
+/****************************************************************************
+ * Name: iob_copyin_iov_internal
+ *
+ * Description:
+ *  Iterate through an array of 'iov' buffers and copy each into the I/O
+ *  buffer chain, updating the offset for each segment.
+ *
+ ****************************************************************************/
+
+static int iob_copyin_iov_internal(FAR struct iob_s *iob,
+                                   FAR const struct iovec *iov,
+                                   unsigned int iovlen, int offset,
+                                   bool throttled, bool block)
+{
+  int total_copied = 0;
+  int ret;
+  unsigned int i;
+
+  if (iob == NULL || iov == NULL || iovlen == 0)
+    {
+      return 0;
+    }
+
+  for (i = 0; i < iovlen; i++)
+    {
+      if (iov[i].iov_len == 0)
+        {
+          continue;
+        }
+
+      if (iov[i].iov_base == NULL)
+        {
+          return -EINVAL;
+        }
+
+      if (iov[i].iov_len > (size_t)(INT_MAX - total_copied) ||
+          (offset >= 0 && iov[i].iov_len > (size_t)(INT_MAX - offset)))

Review Comment:
   remove the cast too



##########
mm/iob/iob_copyout.c:
##########
@@ -111,3 +112,46 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s 
*iob,
 
   return len - remaining;
 }
+
+/****************************************************************************
+ * Name: iob_copyout_iov
+ *
+ * Description:
+ *  Copy data 'len' bytes of data from the I/O buffer chain starting at
+ *  'offset' into the user 'iov' array of buffers.
+ *
+ ****************************************************************************/
+
+int iob_copyout_iov(FAR const struct iovec *iov, unsigned int iovlen,
+                    FAR const struct iob_s *iob, unsigned int len,
+                    int offset)
+{
+  unsigned int total_copied = 0;

Review Comment:
   ditto



##########
mm/iob/iob_copyin.c:
##########
@@ -245,3 +247,91 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t 
*src,
 {
   return iob_copyin_internal(iob, src, len, offset, throttled, false);
 }
+
+/****************************************************************************
+ * Name: iob_copyin_iov_internal
+ *
+ * Description:
+ *  Iterate through an array of 'iov' buffers and copy each into the I/O
+ *  buffer chain, updating the offset for each segment.
+ *
+ ****************************************************************************/
+
+static int iob_copyin_iov_internal(FAR struct iob_s *iob,

Review Comment:
   move to private section(after line 215)



##########
net/can/can_recvmsg.c:
##########
@@ -153,41 +153,41 @@ static inline void can_add_recvlen(FAR struct 
can_recvfrom_s *pstate,
 static size_t can_recvfrom_newdata(FAR struct net_driver_s *dev,
                                    FAR struct can_recvfrom_s *pstate)
 {
-  unsigned int offset;
-  ssize_t recvlen;
-
-#ifdef CONFIG_NET_TIMESTAMP
-  cmsg_store_timestamp(pstate->pr_msg, &dev->d_iob->io_time,
-                       pstate->pr_conn->sconn.s_options);
-#endif
+  unsigned int orig_offset;
+  size_t total_copied = 0;
+  size_t datalen = dev->d_len;

Review Comment:
   why not keep offset/recvlen and remove datalen



##########
mm/iob/iob_copyout.c:
##########
@@ -111,3 +112,46 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s 
*iob,
 
   return len - remaining;
 }
+
+/****************************************************************************
+ * Name: iob_copyout_iov
+ *
+ * Description:
+ *  Copy data 'len' bytes of data from the I/O buffer chain starting at
+ *  'offset' into the user 'iov' array of buffers.
+ *
+ ****************************************************************************/
+
+int iob_copyout_iov(FAR const struct iovec *iov, unsigned int iovlen,
+                    FAR const struct iob_s *iob, unsigned int len,
+                    int offset)
+{
+  unsigned int total_copied = 0;
+  unsigned int datalen = len;
+  int copied;
+  unsigned int i;
+
+  if (iov == NULL || iovlen == 0 || iob == NULL || len == 0)
+    {
+      return 0;
+    }
+
+  for (i = 0; i < iovlen && datalen > 0; i++)
+    {
+      size_t chunk = MIN((size_t)iov[i].iov_len, (size_t)datalen);
+
+      if (chunk > 0 && iov[i].iov_base != NULL)
+        {
+          copied = iob_copyout((FAR uint8_t *)iov[i].iov_base, iob,

Review Comment:
   remove the cast



##########
mm/iob/iob_copyin.c:
##########
@@ -245,3 +247,91 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t 
*src,
 {
   return iob_copyin_internal(iob, src, len, offset, throttled, false);
 }
+
+/****************************************************************************
+ * Name: iob_copyin_iov_internal
+ *
+ * Description:
+ *  Iterate through an array of 'iov' buffers and copy each into the I/O
+ *  buffer chain, updating the offset for each segment.
+ *
+ ****************************************************************************/
+
+static int iob_copyin_iov_internal(FAR struct iob_s *iob,
+                                   FAR const struct iovec *iov,
+                                   unsigned int iovlen, int offset,
+                                   bool throttled, bool block)
+{
+  int total_copied = 0;

Review Comment:
   ```suggestion
     int total = 0;
   ```



##########
mm/iob/iob_copyout.c:
##########
@@ -111,3 +112,46 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s 
*iob,
 
   return len - remaining;
 }
+
+/****************************************************************************
+ * Name: iob_copyout_iov
+ *
+ * Description:
+ *  Copy data 'len' bytes of data from the I/O buffer chain starting at
+ *  'offset' into the user 'iov' array of buffers.
+ *
+ ****************************************************************************/
+
+int iob_copyout_iov(FAR const struct iovec *iov, unsigned int iovlen,
+                    FAR const struct iob_s *iob, unsigned int len,
+                    int offset)
+{
+  unsigned int total_copied = 0;
+  unsigned int datalen = len;
+  int copied;
+  unsigned int i;
+
+  if (iov == NULL || iovlen == 0 || iob == NULL || len == 0)
+    {
+      return 0;
+    }
+
+  for (i = 0; i < iovlen && datalen > 0; i++)
+    {
+      size_t chunk = MIN((size_t)iov[i].iov_len, (size_t)datalen);

Review Comment:
   remove the cast



##########
net/local/local_recvmsg.c:
##########
@@ -540,29 +542,110 @@ ssize_t local_recvmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
 {
   FAR socklen_t *fromlen = &msg->msg_namelen;
   FAR struct sockaddr *from = msg->msg_name;
-  FAR void *buf = msg->msg_iov->iov_base;
-  size_t len = msg->msg_iov->iov_len;
+  FAR void *buf;
+  ssize_t len;
 
-  if (msg->msg_iovlen != 1)
+  if (msg->msg_iovlen == 0)
     {
-      return -ENOTSUP;
+      return -EMSGSIZE;
     }
 
-  DEBUGASSERT(buf);
+  buf = msg->msg_iov->iov_base;
+  len = msg->msg_iov->iov_len;
 
   /* Check for a stream socket */
 
 #ifdef CONFIG_NET_LOCAL_STREAM
   if (psock->s_type == SOCK_STREAM)
     {
-      len = psock_stream_recvfrom(psock, buf, len, flags, from, fromlen);
+      FAR uint8_t *target;
+      size_t peek_offset = 0;
+      ssize_t total_recv = 0;
+      size_t iov_recv;
+      ssize_t ret = 0;
+      int cur_flags;
+      int i;
+
+      for (i = 0; i < msg->msg_iovlen; i++)
+        {
+          if (msg->msg_iov[i].iov_len == 0 ||
+              msg->msg_iov[i].iov_base == NULL)
+            {
+              continue;
+            }
+
+          iov_recv = 0;
+          while (iov_recv < msg->msg_iov[i].iov_len)
+            {
+              cur_flags = flags;
+
+              /* If data has already been received and MSG_WAITALL is not
+               * set, do not block waiting for more data.
+               */
+
+              if (total_recv > 0 && !(flags & MSG_WAITALL))
+                {
+                  cur_flags |= MSG_DONTWAIT;
+                }
+
+              target = (FAR uint8_t *)msg->msg_iov[i].iov_base + iov_recv;
+              ret    = psock_stream_recvfrom(psock, target,

Review Comment:
   but we need receive in one call, otherwise other thread may enter here too



##########
net/inet/inet_sockif.c:
##########
@@ -1839,14 +1839,22 @@ static ssize_t inet_sendto(FAR struct socket *psock, 
FAR const void *buf,
 static ssize_t inet_sendmsg(FAR struct socket *psock,
                             FAR const struct msghdr *msg, int flags)
 {
-  FAR void *buf = msg->msg_iov->iov_base;
-  size_t len = msg->msg_iov->iov_len;
+  FAR void *buf;
+  size_t len;

Review Comment:
   move after line 1847



##########
mm/iob/iob_copyout.c:
##########
@@ -111,3 +112,46 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s 
*iob,
 
   return len - remaining;
 }
+
+/****************************************************************************
+ * Name: iob_copyout_iov
+ *
+ * Description:
+ *  Copy data 'len' bytes of data from the I/O buffer chain starting at
+ *  'offset' into the user 'iov' array of buffers.
+ *
+ ****************************************************************************/
+
+int iob_copyout_iov(FAR const struct iovec *iov, unsigned int iovlen,

Review Comment:
   move to private section



##########
mm/iob/iob_copyout.c:
##########
@@ -111,3 +112,46 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s 
*iob,
 
   return len - remaining;
 }
+
+/****************************************************************************
+ * Name: iob_copyout_iov
+ *
+ * Description:
+ *  Copy data 'len' bytes of data from the I/O buffer chain starting at
+ *  'offset' into the user 'iov' array of buffers.
+ *
+ ****************************************************************************/
+
+int iob_copyout_iov(FAR const struct iovec *iov, unsigned int iovlen,
+                    FAR const struct iob_s *iob, unsigned int len,
+                    int offset)
+{
+  unsigned int total_copied = 0;
+  unsigned int datalen = len;
+  int copied;
+  unsigned int i;
+
+  if (iov == NULL || iovlen == 0 || iob == NULL || len == 0)
+    {
+      return 0;
+    }
+
+  for (i = 0; i < iovlen && datalen > 0; i++)

Review Comment:
   total_copied  < len a`nd remove datalen



-- 
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