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


##########
net/socket/recvmsg.c:
##########
@@ -26,18 +26,215 @@
 
 #include <nuttx/config.h>
 
+#include <sys/param.h>
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
+#include <string.h>
 
 #include <nuttx/cancelpt.h>
 #include <nuttx/fs/fs.h>
+#include <nuttx/fs/uio.h>
+#include <nuttx/kmalloc.h>
 #include <nuttx/net/net.h>
 
 #include "socket/socket.h"
 
 #ifdef CONFIG_NET
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: psock_recvmsg_sock
+ *
+ * Description:
+ *   Let the address family receive into msg.  Return the length of the
+ *   control data in msg->msg_controllen.
+ *
+ * Input Parameters:
+ *   psock    A pointer to a NuttX-specific, internal socket structure
+ *   msg      Buffer to receive the message
+ *   flags    Receive flags
+ *
+ * Returned Value:
+ *   The return value of the si_recvmsg() method of the address family.
+ *
+ ****************************************************************************/
+
+static ssize_t psock_recvmsg_sock(FAR struct socket *psock,
+                                  FAR struct msghdr *msg, int flags)
+{
+  unsigned long msg_controllen;
+  FAR void *msg_control;
+  ssize_t ret;
+
+  /* Save the original cmsg information */
+
+  msg_control         = msg->msg_control;
+  msg_controllen      = msg->msg_controllen;
+
+  ret = psock->s_sockif->si_recvmsg(psock, msg, flags);
+
+  /* Recover the pointer and calculate the cmsg's true data length */
+
+  msg->msg_control    = msg_control;
+  msg->msg_controllen = msg_controllen - msg->msg_controllen;
+
+  return ret;
+}
+
+#ifdef CONFIG_BUILD_KERNEL
+
+/****************************************************************************
+ * Name: psock_recvmsg_copy
+ *
+ * Description:
+ *   In a kernel build, the network can complete the receive in another
+ *   task, where the memory of the caller is not mapped.  So receive the
+ *   data, the address and the control data into kernel memory, and copy
+ *   them to the caller after the receive.  A stream receives up to
+ *   SOCKET_COPY_SIZE bytes per part; a datagram is received whole.
+ *
+ * Input Parameters:
+ *   psock    A pointer to a NuttX-specific, internal socket structure
+ *   msg      Buffer to receive the message
+ *   flags    Receive flags
+ *
+ * Returned Value:
+ *   The number of bytes received, or a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static ssize_t psock_recvmsg_copy(FAR struct socket *psock,

Review Comment:
   the copy need done at recvmsg/sendmsg level not psock_recvmsg/sendmsg level 
since psock_xxx may be called by kernel code directly



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