Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | /*
* Copyright (c) 2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_
#define ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_
/**
* @brief BSD Sockets compatible API
* @defgroup bsd_sockets BSD Sockets compatible API
* @ingroup networking
* @{
*/
#include <toolchain.h>
#include <net/socket_types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct zsock_fd_set {
uint32_t bitset[(CONFIG_POSIX_MAX_FDS + 31) / 32];
} zsock_fd_set;
/**
* @brief Legacy function to poll multiple sockets for events
*
* @details
* @rst
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description. This function is provided to ease porting of
* existing code and not recommended for usage due to its inefficiency,
* use :c:func:`zsock_poll()` instead. In Zephyr this function works only with
* sockets, not arbitrary file descriptors.
* This function is also exposed as ``select()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined (in which case
* it may conflict with generic POSIX ``select()`` function).
* @endrst
*/
__syscall int zsock_select(int nfds, zsock_fd_set *readfds,
zsock_fd_set *writefds,
zsock_fd_set *exceptfds,
struct zsock_timeval *timeout);
/** Number of file descriptors which can be added to zsock_fd_set */
#define ZSOCK_FD_SETSIZE (sizeof(((zsock_fd_set *)0)->bitset) * 8)
/**
* @brief Initialize (clear) fd_set
*
* @details
* @rst
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_ZERO()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
void ZSOCK_FD_ZERO(zsock_fd_set *set);
/**
* @brief Check whether socket is a member of fd_set
*
* @details
* @rst
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_ISSET()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set);
/**
* @brief Remove socket from fd_set
*
* @details
* @rst
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_CLR()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
void ZSOCK_FD_CLR(int fd, zsock_fd_set *set);
/**
* @brief Add socket to fd_set
*
* @details
* @rst
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_SET()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
void ZSOCK_FD_SET(int fd, zsock_fd_set *set);
#ifdef CONFIG_NET_SOCKETS_POSIX_NAMES
#define fd_set zsock_fd_set
#define timeval zsock_timeval
#define FD_SETSIZE ZSOCK_FD_SETSIZE
static inline int select(int nfds, zsock_fd_set *readfds,
zsock_fd_set *writefds, zsock_fd_set *exceptfds,
struct timeval *timeout)
{
return zsock_select(nfds, readfds, writefds, exceptfds, timeout);
}
static inline void FD_ZERO(zsock_fd_set *set)
{
ZSOCK_FD_ZERO(set);
}
static inline int FD_ISSET(int fd, zsock_fd_set *set)
{
return ZSOCK_FD_ISSET(fd, set);
}
static inline void FD_CLR(int fd, zsock_fd_set *set)
{
ZSOCK_FD_CLR(fd, set);
}
static inline void FD_SET(int fd, zsock_fd_set *set)
{
ZSOCK_FD_SET(fd, set);
}
#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */
#ifdef __cplusplus
}
#endif
#include <syscalls/socket_select.h>
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_NET_SOCKET_SELECT_H_ */
|