2023-05-26 22:21:07 +03:00
|
|
|
#ifndef _SYS_SELECT_H
|
|
|
|
#define _SYS_SELECT_H 1
|
|
|
|
|
|
|
|
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2024-02-12 17:26:33 +02:00
|
|
|
#include <bits/types/timeval.h>
|
2023-05-26 22:21:07 +03:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#define FD_SETSIZE 1024
|
|
|
|
|
|
|
|
typedef unsigned long __fd_mask;
|
|
|
|
#define __FD_MASK_SIZE (8 * sizeof(__fd_mask))
|
|
|
|
|
|
|
|
typedef struct {
|
2024-08-09 16:55:52 +03:00
|
|
|
__fd_mask __fds_bits[FD_SETSIZE / __FD_MASK_SIZE];
|
2023-05-26 22:21:07 +03:00
|
|
|
} fd_set;
|
|
|
|
|
|
|
|
#define FD_CLR(fd, setp) \
|
2024-01-24 14:43:46 +02:00
|
|
|
do { \
|
2023-05-26 22:21:07 +03:00
|
|
|
__fd_mask off = (fd) / __FD_MASK_SIZE; \
|
|
|
|
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
|
2024-08-09 16:55:52 +03:00
|
|
|
(setp)->__fds_bits[off] &= ~((__fd_mask)1 << bit); \
|
2023-05-26 22:21:07 +03:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define FD_ISSET(fd, setp) \
|
|
|
|
({ \
|
|
|
|
__fd_mask off = (fd) / __FD_MASK_SIZE; \
|
|
|
|
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
|
2024-08-09 16:55:52 +03:00
|
|
|
(setp)->__fds_bits[off] & ((__fd_mask)1 << bit); \
|
2023-05-26 22:21:07 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
#define FD_SET(fd, setp) \
|
2024-01-24 14:43:46 +02:00
|
|
|
do { \
|
2023-05-26 22:21:07 +03:00
|
|
|
__fd_mask off = (fd) / __FD_MASK_SIZE; \
|
|
|
|
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
|
2024-08-09 16:55:52 +03:00
|
|
|
(setp)->__fds_bits[off] |= ((__fd_mask)1 << bit); \
|
2023-05-26 22:21:07 +03:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define FD_ZERO(setp) \
|
|
|
|
do { \
|
2024-06-18 20:32:43 +03:00
|
|
|
for (int i = 0; i < (int)FD_SETSIZE / (int)__FD_MASK_SIZE; i++) \
|
2024-08-09 16:55:52 +03:00
|
|
|
(setp)->__fds_bits[i] = (__fd_mask)0; \
|
2023-05-26 22:21:07 +03:00
|
|
|
} while (0)
|
|
|
|
|
2024-02-12 17:26:33 +02:00
|
|
|
struct sys_pselect_t
|
|
|
|
{
|
|
|
|
int nfds;
|
|
|
|
fd_set* readfds;
|
|
|
|
fd_set* writefds;
|
|
|
|
fd_set* errorfds;
|
|
|
|
const struct timespec* timeout;
|
|
|
|
const sigset_t* sigmask;
|
|
|
|
};
|
|
|
|
|
2023-05-26 22:21:07 +03:00
|
|
|
int pselect(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, const struct timespec* __restrict timeout, const sigset_t* __restrict sigmask);
|
|
|
|
int select(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, struct timeval* __restrict timeout);
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|