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


##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -92,26 +94,93 @@ static void host_usrsock_set_fd(int fd, fd_set *fds)
     }
 }
 
-static void sockaddr_to_native(const struct nuttx_sockaddr *addr,
-                               const nuttx_socklen_t addrlen,
-                               struct sockaddr *naddr,
-                               socklen_t *naddrlen)
+static int sockaddr_to_native(const struct nuttx_sockaddr *addr,
+                              const nuttx_socklen_t addrlen,

Review Comment:
   remove const



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -248,34 +317,67 @@ static int host_usrsock_sockopt(int sockfd, int level, 
int optname,
 int host_usrsock_socket(int domain, int type, int protocol)
 {
   int opt = 1;
+  int sockflags = 0;
   int ret;
 
   if (domain == NUTTX_PF_INET)

Review Comment:
   let's change to switch?



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -92,26 +94,93 @@ static void host_usrsock_set_fd(int fd, fd_set *fds)
     }
 }
 
-static void sockaddr_to_native(const struct nuttx_sockaddr *addr,
-                               const nuttx_socklen_t addrlen,
-                               struct sockaddr *naddr,
-                               socklen_t *naddrlen)
+static int sockaddr_to_native(const struct nuttx_sockaddr *addr,
+                              const nuttx_socklen_t addrlen,
+                              struct sockaddr_storage *naddr,
+                              socklen_t *naddrlen)
 {
-  naddr->sa_family = addr->sa_family;
-  memcpy(naddr->sa_data, addr->sa_data, sizeof(naddr->sa_data));
+  if (addr == NULL || naddr == NULL || naddrlen == NULL)
+    {
+      return -EINVAL;
+    }
+
+  memset(naddr, 0, sizeof(*naddr));
+
+  if (addr->sa_family == NUTTX_AF_LOCAL)
+    {
+      const struct nuttx_sockaddr_un *un =
+        (const struct nuttx_sockaddr_un *)addr;
+      struct sockaddr_un *native = (struct sockaddr_un *)naddr;
+      size_t pathlen;
 
+      if (addrlen < offsetof(struct nuttx_sockaddr_un, sun_path) + 1)
+        {
+          return -EINVAL;
+        }
+
+      pathlen = strnlen(un->sun_path, sizeof(un->sun_path));
+      if (pathlen >= sizeof(native->sun_path))
+        {
+          return -ENAMETOOLONG;
+        }
+
+      native->sun_family = AF_UNIX;
+      memcpy(native->sun_path, un->sun_path, pathlen + 1);
+      *naddrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;
+
+      return 0;
+    }
+
+  if (addrlen > sizeof(*naddr))
+    {
+      return -ENOSPC;
+    }
+
+  memcpy(naddr, addr, addrlen);
   *naddrlen = addrlen;
+
+  return 0;
 }
 
-static void sockaddr_to_nuttx(const struct sockaddr *naddr,
-                              const socklen_t naddrlen,
-                              struct nuttx_sockaddr *addr,
-                              nuttx_socklen_t *addrlen)
+static int sockaddr_to_nuttx(const struct sockaddr_storage *naddr,
+                             const socklen_t naddrlen,

Review Comment:
   remove const



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -248,34 +317,67 @@ static int host_usrsock_sockopt(int sockfd, int level, 
int optname,
 int host_usrsock_socket(int domain, int type, int protocol)
 {
   int opt = 1;
+  int sockflags = 0;
   int ret;
 
   if (domain == NUTTX_PF_INET)
     {
       domain = PF_INET;
     }
+#ifdef CONFIG_NET_IPv6
+  else if (domain == NUTTX_PF_INET6)
+    {
+      domain = PF_INET6;
+    }
+#endif
+  else if (domain == NUTTX_PF_LOCAL)
+    {
+      domain = PF_UNIX;
+    }
   else
     {
       return -EINVAL;
     }
 
-  if (type == NUTTX_SOCK_STREAM)
+  if ((type & NUTTX_SOCK_TYPE_MASK) == NUTTX_SOCK_STREAM)

Review Comment:
   change to switch too



##########
fs/hostfs/hostfs.c:
##########
@@ -609,6 +610,45 @@ static int hostfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
       return ret;
     }
 
+  /* POSIX file locks reach filesystems as private FIOC_* commands after
+   * fcntl() handling in VFS.  Backends that can forward non-blocking lock
+   * commands to the host may implement host_fcntl().  Other backends return
+   * -ENOTTY so VFS falls back to NuttX internal file locks.  Do not call
+   * blocking host F_SETLKW because it can stop the whole sim OS.
+   */
+
+  if (cmd == FIOC_GETLK)
+    {
+      ret = host_fcntl(hf->fd, F_GETLK, (FAR struct flock *)(uintptr_t)arg);
+      goto out;
+    }
+  else if (cmd == FIOC_SETLK)
+    {
+      ret = host_fcntl(hf->fd, F_SETLK, (FAR struct flock *)(uintptr_t)arg);
+      goto out;
+    }
+  else if (cmd == FIOC_SETLKW)
+    {
+      for (; ; )
+        {
+          ret = host_fcntl(hf->fd, F_SETLK,

Review Comment:
   let's do the convert and loop inside host_fcntl



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