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


##########
include/nuttx/fs/hostfs.h:
##########
@@ -229,20 +262,31 @@ void          host_rewinddir(void *dirp);
 int           host_closedir(void *dirp);
 int           host_statfs(const char *path, struct nuttx_statfs_s *buf);
 int           host_unlink(const char *pathname);
+int           host_remove(const char *pathname);
 int           host_mkdir(const char *pathname, int mode);
 int           host_rmdir(const char *pathname);
 int           host_rename(const char *oldpath, const char *newpath);
 int           host_stat(const char *path, struct nuttx_stat_s *buf);
+int           host_access(const char *path, int mode);
 int           host_chstat(const char *path,
                           const struct nuttx_stat_s *buf, int flags);
+nuttx_file_t  host_popen(const char *command, const char *mode);

Review Comment:
   All functions defined in hostfs.h aren't designed for application developer 
but consumed by https://github.com/apache/nuttx/tree/master/fs/hostfs.
   I don't see that you modify the code under fs/hostfs/ to call new functions.
   BTW, any application which call host_xxx function directly will be locked on 
sim board.



##########
arch/sim/src/sim/sim_hostsocket.h:
##########
@@ -0,0 +1,129 @@
+/****************************************************************************
+ * arch/sim/src/sim/sim_hostsocket.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_SIM_SRC_SIM_HOSTSOCKET_H
+#define __ARCH_SIM_SRC_SIM_HOSTSOCKET_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stdint.h>
+
+#include "sim_hostsock.h"
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+enum host_socket_addr_type
+{
+  HOST_SOCKET_ADDR_HCI,
+  HOST_SOCKET_ADDR_UNIX,
+  HOST_SOCKET_ADDR_IPV4,
+  HOST_SOCKET_ADDR_IPV6,
+  HOST_SOCKET_ADDR_NETLINK,
+};
+
+struct host_socket_addr
+{
+  enum host_socket_addr_type type;
+  union
+  {
+    struct
+    {
+      uint16_t dev;
+      uint16_t channel;
+    } hci;
+
+    struct
+    {
+      char path[108];
+    } un;
+
+    struct
+    {
+      uint8_t addr[4];
+      uint16_t port;
+    } ipv4;
+
+    struct
+    {
+      uint8_t addr[16];
+      uint16_t port;
+    } ipv6;
+
+    struct
+    {
+      uint32_t pid;
+      uint32_t groups;
+    } netlink;
+  };
+};
+
+struct host_addrinfo
+{
+  int flags;
+  int family;
+  int socktype;
+  int protocol;
+  struct host_socket_addr addr;
+  struct host_addrinfo *next;
+};
+
+#define HOST_IFNAMSIZ 64
+
+struct host_ifaddrs
+{
+  struct host_ifaddrs *next;
+  char name[HOST_IFNAMSIZ];
+  unsigned int flags;
+  uint8_t has_addr;
+  struct host_socket_addr addr;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+int host_socket(int domain, int type, int protocol);
+int host_bind(int fd, const struct host_socket_addr *addr);
+int host_connect(int fd, const struct host_socket_addr *addr);

Review Comment:
   it's wrong to call the host socket api directly, since many functions (e.g. 
accept/connect/send/recv) will block the whole system, not just the current 
thread.



##########
arch/sim/src/sim/posix/sim_hostepoll.c:
##########
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * arch/sim/src/sim/posix/sim_hostepoll.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/epoll.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "sim_internal.h"
+#include "sim_hostepoll.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int host_epoll_create1(int flags)
+{
+  int hostflags = 0;
+  int ret;
+
+  if (flags & NUTTX_EPOLL_CLOEXEC)
+    {
+      hostflags |= EPOLL_CLOEXEC;
+      flags &= ~NUTTX_EPOLL_CLOEXEC;
+    }
+
+  if (flags != 0)
+    {
+      return -EINVAL;
+    }
+
+  ret = epoll_create1(hostflags);
+  return ret < 0 ? host_errno_convert(-errno) : ret;
+}
+
+int host_epoll_ctl(int epoll_fd, int op, int fd, uint32_t events,
+                   uintptr_t data)
+{
+  struct epoll_event event;
+  struct epoll_event *eventptr = NULL;
+  int ret;
+
+  memset(&event, 0, sizeof(event));
+
+  if (op != EPOLL_CTL_DEL)
+    {
+      event.events = events;
+      event.data.ptr = (void *)data;
+      eventptr = &event;
+    }
+
+  ret = epoll_ctl(epoll_fd, op, fd, eventptr);
+  return ret < 0 ? host_errno_convert(-errno) : ret;
+}
+
+int host_epoll_wait(int epoll_fd, struct host_epoll_event *events,

Review Comment:
   epoll_wait will block the whole OS, not just the current thread, which is 
definitely not you want behaviour.



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