Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
socket_select.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_
13#define ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_
14
22#include <time.h>
23
24#include <zephyr/toolchain.h>
26#include <zephyr/sys/fdtable.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
34
49static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds,
50 zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
51{
52 struct timespec to = {
53 .tv_sec = (timeout == NULL) ? 0 : timeout->tv_sec,
54 .tv_nsec = (long)((timeout == NULL) ? 0 : timeout->tv_usec * NSEC_PER_USEC)};
55
56 return zvfs_select(nfds, readfds, writefds, exceptfds, (timeout == NULL) ? NULL : &to,
57 NULL);
58}
59
61#define ZSOCK_FD_SETSIZE ZVFS_FD_SETSIZE
62
73static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
74{
75 ZVFS_FD_ZERO(set);
76}
77
88static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
89{
90 return ZVFS_FD_ISSET(fd, set);
91}
92
103static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
104{
105 ZVFS_FD_CLR(fd, set);
106}
107
118static inline void ZSOCK_FD_SET(int fd, zsock_fd_set *set)
119{
120 ZVFS_FD_SET(fd, set);
121}
122
125#ifdef CONFIG_NET_SOCKETS_POSIX_NAMES
126
127#define fd_set zsock_fd_set
128#define FD_SETSIZE ZSOCK_FD_SETSIZE
129
130static inline int select(int nfds, zsock_fd_set *readfds,
131 zsock_fd_set *writefds, zsock_fd_set *exceptfds,
132 struct timeval *timeout)
133{
134 return zsock_select(nfds, readfds, writefds, exceptfds, timeout);
135}
136
137static inline void FD_ZERO(zsock_fd_set *set)
138{
139 ZSOCK_FD_ZERO(set);
140}
141
142static inline int FD_ISSET(int fd, zsock_fd_set *set)
143{
144 return ZSOCK_FD_ISSET(fd, set);
145}
146
147static inline void FD_CLR(int fd, zsock_fd_set *set)
148{
149 ZSOCK_FD_CLR(fd, set);
150}
151
152static inline void FD_SET(int fd, zsock_fd_set *set)
153{
154 ZSOCK_FD_SET(fd, set);
155}
156
157#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */
158
161#ifdef __cplusplus
162}
163#endif
164
169#endif /* ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_ */
void ZVFS_FD_CLR(int fd, struct zvfs_fd_set *fdset)
void ZVFS_FD_ZERO(struct zvfs_fd_set *fdset)
int ZVFS_FD_ISSET(int fd, struct zvfs_fd_set *fdset)
int zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds, struct zvfs_fd_set *ZRESTRICT writefds, struct zvfs_fd_set *ZRESTRICT errorfds, const struct timespec *ZRESTRICT timeout, const void *ZRESTRICT sigmask)
void ZVFS_FD_SET(int fd, struct zvfs_fd_set *fdset)
static int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds, zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
Legacy function to poll multiple sockets for events.
Definition socket_select.h:49
static void ZSOCK_FD_SET(int fd, zsock_fd_set *set)
Add socket to fd_set.
Definition socket_select.h:118
static void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
Remove socket from fd_set.
Definition socket_select.h:103
static void ZSOCK_FD_ZERO(zsock_fd_set *set)
Initialize (clear) fd_set.
Definition socket_select.h:73
static int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
Check whether socket is a member of fd_set.
Definition socket_select.h:88
#define NSEC_PER_USEC
number of nanoseconds per micorsecond
Definition sys_clock.h:83
void FD_CLR(int fd, fd_set *fdset)
void FD_ZERO(fd_set *fdset)
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
void FD_SET(int fd, fd_set *fdset)
int FD_ISSET(int fd, fd_set *fdset)
socket types definitionis
Definition _timespec.h:22
Definition _timeval.h:22
Definition fdtable.h:226
Macros to abstract toolchain specific capabilities.