Loading...
Searching...
No Matches
select.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
29#ifndef SYS_SELECT_H
30#define SYS_SELECT_H
31
32#include <string.h>
33/* prevent cyclic dependency with newlib/picolibc's `sys/types.h` */
34#if (defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)) && !defined(CPU_ESP8266)
35#include <sys/_timeval.h>
36#else
37#include <sys/time.h>
38#endif
39
40#include "bitfield.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
57#ifndef CONFIG_POSIX_FD_SET_SIZE
58#define CONFIG_POSIX_FD_SET_SIZE (16)
59#endif
65#define POSIX_SELECT_THREAD_FLAG (1U << 3)
66
67/* ESP's newlib has this already defined in `sys/types.h` */
68#if !defined(CPU_ESP8266)
74#define FD_SETSIZE (CONFIG_POSIX_FD_SET_SIZE)
75
79typedef struct {
82} fd_set;
83
90static inline void FD_CLR(int fd, fd_set *fdsetp)
91{
92 bf_unset(fdsetp->fds, fd);
93}
94
104static inline int FD_ISSET(int fd, fd_set *fdsetp)
105{
106 return (int)bf_isset(fdsetp->fds, fd);
107}
108
116static inline void FD_SET(int fd, fd_set *fdsetp)
117{
118 bf_set(fdsetp->fds, fd);
119}
120
126static inline void FD_ZERO(fd_set *fdsetp)
127{
128 memset(fdsetp->fds, 0, sizeof(fdsetp->fds));
129}
130#endif /* !defined(CPU_ESP32) && !defined(CPU_ESP8266) */
131
164int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
165 struct timeval *timeout);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* SYS_SELECT_H */
bitfields operations on bitfields of arbitrary length
static void bf_set(uint8_t field[], size_t idx)
Set the bit to 1.
Definition bitfield.h:56
static void bf_unset(uint8_t field[], size_t idx)
Clear the bit.
Definition bitfield.h:80
static bool bf_isset(const uint8_t field[], size_t idx)
Check if the bet is set.
Definition bitfield.h:128
static int FD_ISSET(int fd, fd_set *fdsetp)
Checks if a file descriptor is a member of an fd_set
Definition select.h:104
static void FD_SET(int fd, fd_set *fdsetp)
Adds a file descriptor from an fd_set if it is not already a member.
Definition select.h:116
static void FD_ZERO(fd_set *fdsetp)
Initializes the descriptor set as an empty set.
Definition select.h:126
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
Examines the given file descriptor sets if they are ready for their respective operation.
#define FD_SETSIZE
Maximum number of file descriptors in an fd_set structure.
Definition select.h:74
static void FD_CLR(int fd, fd_set *fdsetp)
Removes a file descriptor from an fd_set if it is a member.
Definition select.h:90
The fd_set structure.
Definition select.h:79
BITFIELD(fds, FD_SETSIZE)
Bit-field to represent the set of file descriptors.
Definition of struct timeval for the atmega.
Definition time.h:23