arch/sim: Change usrsock_host_ prefix to host_usrsock_

to align with other similar function style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-12-04 16:20:28 +08:00 committed by Petro Karashchenko
parent 79c8b7d3fd
commit d6c8c269f5
4 changed files with 71 additions and 71 deletions

View File

@ -57,7 +57,7 @@ static fd_set g_active_write_fds;
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static void usrsock_host_clear_fd(int fd, fd_set *fds) static void host_usrsock_clear_fd(int fd, fd_set *fds)
{ {
if (FD_ISSET(fd, fds)) if (FD_ISSET(fd, fds))
{ {
@ -82,7 +82,7 @@ static void usrsock_host_clear_fd(int fd, fd_set *fds)
} }
} }
static void usrsock_host_set_fd(int fd, fd_set *fds) static void host_usrsock_set_fd(int fd, fd_set *fds)
{ {
if (!FD_ISSET(fd, fds)) if (!FD_ISSET(fd, fds))
{ {
@ -128,7 +128,7 @@ static void sock_nonblock(int socket, int enable)
} }
} }
static int usrsock_host_sockopt(int sockfd, int level, int optname, static int host_usrsock_sockopt(int sockfd, int level, int optname,
const void *optval, nuttx_socklen_t *optlen, const void *optval, nuttx_socklen_t *optlen,
bool set) bool set)
{ {
@ -185,7 +185,7 @@ static int usrsock_host_sockopt(int sockfd, int level, int optname,
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
int usrsock_host_socket(int domain, int type, int protocol) int host_usrsock_socket(int domain, int type, int protocol)
{ {
int opt = 1; int opt = 1;
int ret; int ret;
@ -246,20 +246,20 @@ int usrsock_host_socket(int domain, int type, int protocol)
setsockopt(ret, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(ret, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
sock_nonblock(ret, true); sock_nonblock(ret, true);
usrsock_host_set_fd(ret, &g_active_read_fds); host_usrsock_set_fd(ret, &g_active_read_fds);
return ret; return ret;
} }
int usrsock_host_close(int sockfd) int host_usrsock_close(int sockfd)
{ {
usrsock_host_clear_fd(sockfd, &g_active_read_fds); host_usrsock_clear_fd(sockfd, &g_active_read_fds);
usrsock_host_clear_fd(sockfd, &g_active_write_fds); host_usrsock_clear_fd(sockfd, &g_active_write_fds);
return close(sockfd); return close(sockfd);
} }
int usrsock_host_connect(int sockfd, int host_usrsock_connect(int sockfd,
const struct nuttx_sockaddr *addr, const struct nuttx_sockaddr *addr,
nuttx_socklen_t addrlen) nuttx_socklen_t addrlen)
{ {
@ -277,12 +277,12 @@ int usrsock_host_connect(int sockfd,
return -errno; return -errno;
} }
usrsock_host_set_fd(sockfd, &g_active_read_fds); host_usrsock_set_fd(sockfd, &g_active_read_fds);
return ret; return ret;
} }
ssize_t usrsock_host_sendto(int sockfd, const void *buf, ssize_t host_usrsock_sendto(int sockfd, const void *buf,
size_t len, int flags, size_t len, int flags,
const struct nuttx_sockaddr *dest_addr, const struct nuttx_sockaddr *dest_addr,
nuttx_socklen_t addrlen) nuttx_socklen_t addrlen)
@ -305,7 +305,7 @@ ssize_t usrsock_host_sendto(int sockfd, const void *buf,
{ {
if (errno == EAGAIN) if (errno == EAGAIN)
{ {
usrsock_host_set_fd(sockfd, &g_active_write_fds); host_usrsock_set_fd(sockfd, &g_active_write_fds);
} }
else else
{ {
@ -316,7 +316,7 @@ ssize_t usrsock_host_sendto(int sockfd, const void *buf,
return ret >= 0 ? ret : -errno; return ret >= 0 ? ret : -errno;
} }
ssize_t usrsock_host_recvfrom(int sockfd, void *buf, size_t len, int flags, ssize_t host_usrsock_recvfrom(int sockfd, void *buf, size_t len, int flags,
struct nuttx_sockaddr *src_addr, struct nuttx_sockaddr *src_addr,
nuttx_socklen_t *addrlen) nuttx_socklen_t *addrlen)
{ {
@ -349,26 +349,26 @@ ssize_t usrsock_host_recvfrom(int sockfd, void *buf, size_t len, int flags,
sockaddr_to_nuttx(&naddr, naddrlen, src_addr, addrlen); sockaddr_to_nuttx(&naddr, naddrlen, src_addr, addrlen);
} }
usrsock_host_set_fd(sockfd, &g_active_read_fds); host_usrsock_set_fd(sockfd, &g_active_read_fds);
return ret; return ret;
} }
int usrsock_host_setsockopt(int sockfd, int level, int optname, int host_usrsock_setsockopt(int sockfd, int level, int optname,
const void *optval, nuttx_socklen_t optlen) const void *optval, nuttx_socklen_t optlen)
{ {
return usrsock_host_sockopt(sockfd, level, optname, return host_usrsock_sockopt(sockfd, level, optname,
optval, &optlen, true); optval, &optlen, true);
} }
int usrsock_host_getsockopt(int sockfd, int level, int optname, int host_usrsock_getsockopt(int sockfd, int level, int optname,
void *optval, nuttx_socklen_t *optlen) void *optval, nuttx_socklen_t *optlen)
{ {
return usrsock_host_sockopt(sockfd, level, optname, return host_usrsock_sockopt(sockfd, level, optname,
optval, optlen, false); optval, optlen, false);
} }
int usrsock_host_getsockname(int sockfd, int host_usrsock_getsockname(int sockfd,
struct nuttx_sockaddr *addr, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen) nuttx_socklen_t *addrlen)
{ {
@ -390,7 +390,7 @@ int usrsock_host_getsockname(int sockfd,
return ret; return ret;
} }
int usrsock_host_getpeername(int sockfd, int host_usrsock_getpeername(int sockfd,
struct nuttx_sockaddr *addr, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen) nuttx_socklen_t *addrlen)
{ {
@ -412,7 +412,7 @@ int usrsock_host_getpeername(int sockfd,
return ret; return ret;
} }
int usrsock_host_bind(int sockfd, int host_usrsock_bind(int sockfd,
const struct nuttx_sockaddr *addr, const struct nuttx_sockaddr *addr,
nuttx_socklen_t addrlen) nuttx_socklen_t addrlen)
{ {
@ -424,7 +424,7 @@ int usrsock_host_bind(int sockfd,
return bind(sockfd, &naddr, naddrlen) < 0 ? -errno : 0; return bind(sockfd, &naddr, naddrlen) < 0 ? -errno : 0;
} }
int usrsock_host_listen(int sockfd, int backlog) int host_usrsock_listen(int sockfd, int backlog)
{ {
int ret; int ret;
@ -434,12 +434,12 @@ int usrsock_host_listen(int sockfd, int backlog)
return -errno; return -errno;
} }
usrsock_host_set_fd(sockfd, &g_active_read_fds); host_usrsock_set_fd(sockfd, &g_active_read_fds);
return ret; return ret;
} }
int usrsock_host_accept(int sockfd, struct nuttx_sockaddr *addr, int host_usrsock_accept(int sockfd, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen) nuttx_socklen_t *addrlen)
{ {
socklen_t naddrlen = sizeof(socklen_t); socklen_t naddrlen = sizeof(socklen_t);
@ -458,18 +458,18 @@ int usrsock_host_accept(int sockfd, struct nuttx_sockaddr *addr,
} }
sock_nonblock(ret, true); sock_nonblock(ret, true);
usrsock_host_set_fd(ret, &g_active_read_fds); host_usrsock_set_fd(ret, &g_active_read_fds);
usrsock_host_set_fd(sockfd, &g_active_read_fds); host_usrsock_set_fd(sockfd, &g_active_read_fds);
return ret; return ret;
} }
int usrsock_host_ioctl(int fd, unsigned long request, ...) int host_usrsock_ioctl(int fd, unsigned long request, ...)
{ {
return 0; return 0;
} }
void usrsock_host_loop(void) void host_usrsock_loop(void)
{ {
struct timeval timeout; struct timeval timeout;
fd_set write_fds; fd_set write_fds;
@ -499,13 +499,13 @@ void usrsock_host_loop(void)
if (FD_ISSET(i, &read_fds)) if (FD_ISSET(i, &read_fds))
{ {
usrsock_host_clear_fd(i, &g_active_read_fds); host_usrsock_clear_fd(i, &g_active_read_fds);
events |= NUTTX_USRSOCK_EVENT_RECVFROM_AVAIL; events |= NUTTX_USRSOCK_EVENT_RECVFROM_AVAIL;
} }
if (FD_ISSET(i, &write_fds)) if (FD_ISSET(i, &write_fds))
{ {
usrsock_host_clear_fd(i, &g_active_write_fds); host_usrsock_clear_fd(i, &g_active_write_fds);
events |= NUTTX_USRSOCK_EVENT_SENDTO_READY; events |= NUTTX_USRSOCK_EVENT_SENDTO_READY;
} }

View File

@ -258,60 +258,60 @@ struct nuttx_cmsghdr
#ifdef __SIM__ #ifdef __SIM__
int usrsock_event_callback(int16_t usockid, uint16_t events); int usrsock_event_callback(int16_t usockid, uint16_t events);
int usrsock_host_socket(int domain, int type, int protocol); int host_usrsock_socket(int domain, int type, int protocol);
int usrsock_host_close(int sockfd); int host_usrsock_close(int sockfd);
int usrsock_host_connect(int sockfd, const struct nuttx_sockaddr *addr, int host_usrsock_connect(int sockfd, const struct nuttx_sockaddr *addr,
nuttx_socklen_t addrlen); nuttx_socklen_t addrlen);
ssize_t usrsock_host_sendto(int sockfd, const void *buf, size_t len, ssize_t host_usrsock_sendto(int sockfd, const void *buf, size_t len,
int flags, int flags,
const struct nuttx_sockaddr *dest_addr, const struct nuttx_sockaddr *dest_addr,
nuttx_socklen_t addrlen); nuttx_socklen_t addrlen);
ssize_t usrsock_host_recvfrom(int sockfd, void *buf, size_t len, int flags, ssize_t host_usrsock_recvfrom(int sockfd, void *buf, size_t len, int flags,
struct nuttx_sockaddr *src_addr, struct nuttx_sockaddr *src_addr,
nuttx_socklen_t *addrlen); nuttx_socklen_t *addrlen);
int usrsock_host_setsockopt(int sockfd, int level, int optname, int host_usrsock_setsockopt(int sockfd, int level, int optname,
const void *optval, nuttx_socklen_t optlen); const void *optval, nuttx_socklen_t optlen);
int usrsock_host_getsockopt(int sockfd, int level, int optname, int host_usrsock_getsockopt(int sockfd, int level, int optname,
void *optval, nuttx_socklen_t *optlen); void *optval, nuttx_socklen_t *optlen);
int usrsock_host_getsockname(int sockfd, int host_usrsock_getsockname(int sockfd,
struct nuttx_sockaddr *addr, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen); nuttx_socklen_t *addrlen);
int usrsock_host_getpeername(int sockfd, int host_usrsock_getpeername(int sockfd,
struct nuttx_sockaddr *addr, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen); nuttx_socklen_t *addrlen);
int usrsock_host_bind(int sockfd, const struct nuttx_sockaddr *addr, int host_usrsock_bind(int sockfd, const struct nuttx_sockaddr *addr,
nuttx_socklen_t addrlen); nuttx_socklen_t addrlen);
int usrsock_host_listen(int sockfd, int backlog); int host_usrsock_listen(int sockfd, int backlog);
int usrsock_host_accept(int sockfd, struct nuttx_sockaddr *addr, int host_usrsock_accept(int sockfd, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen); nuttx_socklen_t *addrlen);
int usrsock_host_ioctl(int fd, unsigned long request, ...); int host_usrsock_ioctl(int fd, unsigned long request, ...);
#else #else
int usrsock_host_socket(int domain, int type, int protocol); int host_usrsock_socket(int domain, int type, int protocol);
int usrsock_host_close(int sockfd); int host_usrsock_close(int sockfd);
int usrsock_host_connect(int sockfd, const struct sockaddr *addr, int host_usrsock_connect(int sockfd, const struct sockaddr *addr,
socklen_t addrlen); socklen_t addrlen);
ssize_t usrsock_host_sendto(int sockfd, const void *buf, size_t len, ssize_t host_usrsock_sendto(int sockfd, const void *buf, size_t len,
int flags, int flags,
const struct sockaddr *dest_addr, const struct sockaddr *dest_addr,
socklen_t addrlen); socklen_t addrlen);
ssize_t usrsock_host_recvfrom(int sockfd, void *buf, size_t len, int flags, ssize_t host_usrsock_recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, struct sockaddr *src_addr,
socklen_t *addrlen); socklen_t *addrlen);
int usrsock_host_setsockopt(int sockfd, int level, int optname, int host_usrsock_setsockopt(int sockfd, int level, int optname,
const void *optval, socklen_t optlen); const void *optval, socklen_t optlen);
int usrsock_host_getsockopt(int sockfd, int level, int optname, int host_usrsock_getsockopt(int sockfd, int level, int optname,
void *optval, socklen_t *optlen); void *optval, socklen_t *optlen);
int usrsock_host_getsockname(int sockfd, struct sockaddr *addr, int host_usrsock_getsockname(int sockfd, struct sockaddr *addr,
socklen_t *addrlen); socklen_t *addrlen);
int usrsock_host_getpeername(int sockfd, struct sockaddr *addr, int host_usrsock_getpeername(int sockfd, struct sockaddr *addr,
socklen_t *addrlen); socklen_t *addrlen);
int usrsock_host_bind(int sockfd, const struct sockaddr *addr, int host_usrsock_bind(int sockfd, const struct sockaddr *addr,
socklen_t addrlen); socklen_t addrlen);
int usrsock_host_listen(int sockfd, int backlog); int host_usrsock_listen(int sockfd, int backlog);
int usrsock_host_accept(int sockfd, struct sockaddr *addr, int host_usrsock_accept(int sockfd, struct sockaddr *addr,
socklen_t *addrlen); socklen_t *addrlen);
int usrsock_host_ioctl(int fd, unsigned long request, ...); int host_usrsock_ioctl(int fd, unsigned long request, ...);
void usrsock_host_loop(void); void host_usrsock_loop(void);
#endif /* __SIM__ */ #endif /* __SIM__ */
#endif /* __ARCH_SIM_SRC_SIM_HOSTUSRSOCK_H */ #endif /* __ARCH_SIM_SRC_SIM_HOSTUSRSOCK_H */

View File

@ -180,7 +180,7 @@ static int sim_loop_task(int argc, char **argv)
#endif #endif
#ifdef CONFIG_SIM_NETUSRSOCK #ifdef CONFIG_SIM_NETUSRSOCK
usrsock_host_loop(); host_usrsock_loop();
#endif #endif
#ifdef CONFIG_RPTUN #ifdef CONFIG_RPTUN

View File

@ -132,7 +132,7 @@ static int usrsock_socket_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_socket_s *req = data; const struct usrsock_request_socket_s *req = data;
int fd = usrsock_host_socket(req->domain, req->type, req->protocol); int fd = host_usrsock_socket(req->domain, req->type, req->protocol);
int ret = usrsock_send_ack(usrsock, req->head.xid, fd); int ret = usrsock_send_ack(usrsock, req->head.xid, fd);
if (ret >= 0 && fd >= 0) if (ret >= 0 && fd >= 0)
@ -147,7 +147,7 @@ static int usrsock_close_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_close_s *req = data; const struct usrsock_request_close_s *req = data;
int ret = usrsock_host_close(req->usockid); int ret = host_usrsock_close(req->usockid);
return usrsock_send_ack(usrsock, req->head.xid, ret); return usrsock_send_ack(usrsock, req->head.xid, ret);
} }
@ -156,7 +156,7 @@ static int usrsock_connect_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_connect_s *req = data; const struct usrsock_request_connect_s *req = data;
int ret = usrsock_host_connect(req->usockid, int ret = host_usrsock_connect(req->usockid,
(const struct sockaddr *)(req + 1), (const struct sockaddr *)(req + 1),
req->addrlen); req->addrlen);
@ -167,7 +167,7 @@ static int usrsock_sendto_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_sendto_s *req = data; const struct usrsock_request_sendto_s *req = data;
int ret = usrsock_host_sendto(req->usockid, int ret = host_usrsock_sendto(req->usockid,
(const void *)(req + 1) + req->addrlen, (const void *)(req + 1) + req->addrlen,
req->buflen, req->flags, req->buflen, req->flags,
req->addrlen ? req->addrlen ?
@ -201,7 +201,7 @@ static int usrsock_recvfrom_handler(struct usrsock_s *usrsock,
buflen = sizeof(usrsock->out) - sizeof(*ack) - inaddrlen; buflen = sizeof(usrsock->out) - sizeof(*ack) - inaddrlen;
} }
ret = usrsock_host_recvfrom(req->usockid, ret = host_usrsock_recvfrom(req->usockid,
(void *)(ack + 1) + inaddrlen, (void *)(ack + 1) + inaddrlen,
buflen, req->flags, buflen, req->flags,
outaddrlen ? outaddrlen ?
@ -221,7 +221,7 @@ static int usrsock_setsockopt_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_setsockopt_s *req = data; const struct usrsock_request_setsockopt_s *req = data;
int ret = usrsock_host_setsockopt(req->usockid, req->level, int ret = host_usrsock_setsockopt(req->usockid, req->level,
req->option, req + 1, req->valuelen); req->option, req + 1, req->valuelen);
return usrsock_send_ack(usrsock, req->head.xid, ret); return usrsock_send_ack(usrsock, req->head.xid, ret);
@ -236,7 +236,7 @@ static int usrsock_getsockopt_handler(struct usrsock_s *usrsock,
int ret; int ret;
ack = (struct usrsock_message_datareq_ack_s *)usrsock->out; ack = (struct usrsock_message_datareq_ack_s *)usrsock->out;
ret = usrsock_host_getsockopt(req->usockid, ret = host_usrsock_getsockopt(req->usockid,
req->level, req->option, req->level, req->option,
ack + 1, &optlen); ack + 1, &optlen);
@ -254,7 +254,7 @@ static int usrsock_getsockname_handler(struct usrsock_s *usrsock,
int ret; int ret;
ack = (struct usrsock_message_datareq_ack_s *)usrsock->out; ack = (struct usrsock_message_datareq_ack_s *)usrsock->out;
ret = usrsock_host_getsockname(req->usockid, ret = host_usrsock_getsockname(req->usockid,
(struct sockaddr *)(ack + 1), &outaddrlen); (struct sockaddr *)(ack + 1), &outaddrlen);
return usrsock_send_dack(usrsock, ack, req->head.xid, return usrsock_send_dack(usrsock, ack, req->head.xid,
@ -271,7 +271,7 @@ static int usrsock_getpeername_handler(struct usrsock_s *usrsock,
int ret; int ret;
ack = (struct usrsock_message_datareq_ack_s *)usrsock->out; ack = (struct usrsock_message_datareq_ack_s *)usrsock->out;
ret = usrsock_host_getpeername(req->usockid, ret = host_usrsock_getpeername(req->usockid,
(struct sockaddr *)(ack + 1), &outaddrlen); (struct sockaddr *)(ack + 1), &outaddrlen);
return usrsock_send_dack(usrsock, ack, req->head.xid, return usrsock_send_dack(usrsock, ack, req->head.xid,
@ -282,7 +282,7 @@ static int usrsock_bind_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_bind_s *req = data; const struct usrsock_request_bind_s *req = data;
int ret = usrsock_host_bind(req->usockid, int ret = host_usrsock_bind(req->usockid,
(const struct sockaddr *)(req + 1), (const struct sockaddr *)(req + 1),
req->addrlen); req->addrlen);
@ -293,7 +293,7 @@ static int usrsock_listen_handler(struct usrsock_s *usrsock,
const void *data, size_t len) const void *data, size_t len)
{ {
const struct usrsock_request_listen_s *req = data; const struct usrsock_request_listen_s *req = data;
int ret = usrsock_host_listen(req->usockid, req->backlog); int ret = host_usrsock_listen(req->usockid, req->backlog);
return usrsock_send_ack(usrsock, req->head.xid, ret); return usrsock_send_ack(usrsock, req->head.xid, ret);
} }
@ -309,7 +309,7 @@ static int usrsock_accept_handler(struct usrsock_s *usrsock,
int ret; int ret;
ack = (struct usrsock_message_datareq_ack_s *)usrsock->out; ack = (struct usrsock_message_datareq_ack_s *)usrsock->out;
sockfd = usrsock_host_accept(req->usockid, sockfd = host_usrsock_accept(req->usockid,
outaddrlen ? outaddrlen ?
(struct sockaddr *)(ack + 1) : NULL, (struct sockaddr *)(ack + 1) : NULL,
outaddrlen ? &outaddrlen : NULL); outaddrlen ? &outaddrlen : NULL);
@ -352,7 +352,7 @@ static int usrsock_ioctl_handler(struct usrsock_s *usrsock,
ack = (struct usrsock_message_datareq_ack_s *)usrsock->out; ack = (struct usrsock_message_datareq_ack_s *)usrsock->out;
memcpy(ack + 1, req + 1, req->arglen); memcpy(ack + 1, req + 1, req->arglen);
ret = usrsock_host_ioctl(req->usockid, req->cmd, ret = host_usrsock_ioctl(req->usockid, req->cmd,
(unsigned long)(ack + 1)); (unsigned long)(ack + 1));
return usrsock_send_dack(usrsock, ack, req->head.xid, ret, return usrsock_send_dack(usrsock, ack, req->head.xid, ret,