diff --git a/arch/sim/src/sim/up_initialize.c b/arch/sim/src/sim/up_initialize.c index d64a94814bb..27a1264fbb5 100644 --- a/arch/sim/src/sim/up_initialize.c +++ b/arch/sim/src/sim/up_initialize.c @@ -34,6 +34,7 @@ #include #include "up_internal.h" +#include "up_usrsock_host.h" /**************************************************************************** * Private Functions @@ -179,7 +180,7 @@ static int up_loop_task(int argc, char **argv) #endif #ifdef CONFIG_SIM_NETUSRSOCK - usrsock_loop(); + usrsock_host_loop(); #endif #ifdef CONFIG_RPTUN @@ -260,12 +261,6 @@ void up_initialize(void) netdriver_init(); /* Our "real" network driver */ #endif -#ifdef CONFIG_SIM_NETUSRSOCK - /* Register the usrsock native socket device */ - - usrsock_init(); -#endif - #if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_MTD_SMART) && \ (defined(CONFIG_SPI_FLASH) || defined(CONFIG_QSPI_FLASH)) up_init_smartfs(); diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index b9cb0c9d4e7..5c6247e6b1a 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -317,13 +317,6 @@ void netdriver_setmacaddr(unsigned char *macaddr); void netdriver_setmtu(int mtu); void netdriver_loop(void); -/* up_usrsock.c *************************************************************/ - -#ifdef CONFIG_SIM_NETUSRSOCK -int usrsock_init(void); -void usrsock_loop(void); -#endif - /* up_rptun.c ***************************************************************/ #ifdef CONFIG_RPTUN diff --git a/arch/sim/src/sim/up_usrsock.c b/arch/sim/src/sim/up_usrsock.c index f3548b1b565..6c4fc98c4a0 100644 --- a/arch/sim/src/sim/up_usrsock.c +++ b/arch/sim/src/sim/up_usrsock.c @@ -24,13 +24,10 @@ #include -#include #include -#include #include #include -#include #include #include "up_usrsock_host.h" @@ -47,9 +44,8 @@ struct usrsock_s { - struct file usock; - uint8_t in [SIM_USRSOCK_BUFSIZE]; - uint8_t out[SIM_USRSOCK_BUFSIZE]; + uint8_t in[SIM_USRSOCK_BUFSIZE]; + uint8_t out[SIM_USRSOCK_BUFSIZE]; }; /**************************************************************************** @@ -72,22 +68,7 @@ static struct usrsock_s g_usrsock; static int usrsock_send(struct usrsock_s *usrsock, const void *buf, size_t len) { - uint8_t *data = (uint8_t *)buf; - ssize_t ret; - - while (len > 0) - { - ret = file_write(&usrsock->usock, data, len); - if (ret < 0) - { - return ret; - } - - data += ret; - len -= ret; - } - - return 0; + return usrsock_response(buf, len, NULL); } static int usrsock_send_ack(struct usrsock_s *usrsock, @@ -404,47 +385,46 @@ int usrsock_event_callback(int16_t usockid, uint16_t events) return usrsock_send_event(&g_usrsock, usockid, events); } -int usrsock_init(void) +void usrsock_register(void) { - return file_open(&g_usrsock.usock, "/dev/usrsock", O_RDWR); } -void usrsock_loop(void) +/**************************************************************************** + * Name: usrsock_request + ****************************************************************************/ + +int usrsock_request(FAR struct iovec *iov, unsigned int iovcnt) { struct usrsock_request_common_s *common; int ret; - struct pollfd pfd = - { - .ptr = &g_usrsock.usock, - .events = POLLIN | POLLFILE, - }; - ret = poll(&pfd, 1, 0); - if (ret > 0) - { - ret = file_read(&g_usrsock.usock, g_usrsock.in, sizeof(g_usrsock.in)); - if (ret > 0) - { - common = (struct usrsock_request_common_s *)g_usrsock.in; + /* Copy request to buffer */ - if (common->reqid >= 0 && - common->reqid < USRSOCK_REQUEST__MAX) - { - ret = g_usrsock_handler[common->reqid](&g_usrsock, - g_usrsock.in, ret); - if (ret < 0) - { - syslog(LOG_ERR, "Usrsock request %d failed: %d\n", - common->reqid, ret); - } - } - else - { - syslog(LOG_ERR, "Invalid request id: %d\n", - common->reqid); - } - } + ret = usrsock_iovec_get(g_usrsock.in, sizeof(g_usrsock.in), + iov, iovcnt, 0); + if (ret <= 0) + { + return ret; } - usrsock_host_loop(); + common = (struct usrsock_request_common_s *)g_usrsock.in; + + if (common->reqid >= 0 && + common->reqid < USRSOCK_REQUEST__MAX) + { + ret = g_usrsock_handler[common->reqid](&g_usrsock, + g_usrsock.in, ret); + if (ret < 0) + { + syslog(LOG_ERR, "Usrsock request %d failed: %d\n", + common->reqid, ret); + } + } + else + { + syslog(LOG_ERR, "Invalid request id: %d\n", + common->reqid); + } + + return ret; } diff --git a/arch/sim/src/sim/up_usrsock_host.h b/arch/sim/src/sim/up_usrsock_host.h index 748cb668e19..e623ab25a0e 100644 --- a/arch/sim/src/sim/up_usrsock_host.h +++ b/arch/sim/src/sim/up_usrsock_host.h @@ -311,7 +311,6 @@ int usrsock_host_listen(int sockfd, int backlog); int usrsock_host_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); int usrsock_host_ioctl(int fd, unsigned long request, ...); - void usrsock_host_loop(void); #endif /* __SIM__ */ diff --git a/boards/sim/sim/sim/configs/adb/defconfig b/boards/sim/sim/sim/configs/adb/defconfig index 0244847e51d..d8694a5918e 100644 --- a/boards/sim/sim/sim/configs/adb/defconfig +++ b/boards/sim/sim/sim/configs/adb/defconfig @@ -31,6 +31,7 @@ CONFIG_NET_ICMP_NO_STACK=y CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP_NO_STACK=y CONFIG_NET_UDP_NO_STACK=y +CONFIG_NET_USRSOCK_CUSTOM=y CONFIG_NET_USRSOCK_OTHER=y CONFIG_NET_USRSOCK_TCP=y CONFIG_NET_USRSOCK_UDP=y diff --git a/boards/sim/sim/sim/configs/vncserver/defconfig b/boards/sim/sim/sim/configs/vncserver/defconfig index 145b07f90d9..3f257c195d0 100644 --- a/boards/sim/sim/sim/configs/vncserver/defconfig +++ b/boards/sim/sim/sim/configs/vncserver/defconfig @@ -20,6 +20,7 @@ CONFIG_NET=y CONFIG_NET_ICMP_NO_STACK=y CONFIG_NET_TCP_NO_STACK=y CONFIG_NET_UDP_NO_STACK=y +CONFIG_NET_USRSOCK_CUSTOM=y CONFIG_NET_USRSOCK_OTHER=y CONFIG_NET_USRSOCK_TCP=y CONFIG_NET_USRSOCK_UDP=y diff --git a/include/nuttx/net/usrsock.h b/include/nuttx/net/usrsock.h index 0bad2553dc2..1da69b906fe 100644 --- a/include/nuttx/net/usrsock.h +++ b/include/nuttx/net/usrsock.h @@ -29,6 +29,7 @@ #include #include +#include #include #include