2021-07-21 01:43:48 +08:00
|
|
|
/*
|
2022-06-19 21:56:24 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2021-07-21 01:43:48 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-07-21 Meco Man The first version
|
2021-12-23 08:21:52 +08:00
|
|
|
* 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
|
2021-07-21 01:43:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SYS_SELECT_H__
|
|
|
|
#define __SYS_SELECT_H__
|
|
|
|
|
2022-11-23 10:40:50 +08:00
|
|
|
#include <rtconfig.h>
|
2021-07-21 01:43:48 +08:00
|
|
|
#include <sys/types.h>
|
2021-09-15 08:49:44 +08:00
|
|
|
#include <sys/time.h>
|
2023-12-28 14:26:19 +08:00
|
|
|
#include <string.h>
|
2021-07-21 01:43:48 +08:00
|
|
|
|
2022-04-02 16:21:45 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-07-21 01:43:48 +08:00
|
|
|
#ifndef FD_SETSIZE
|
|
|
|
#define FD_SETSIZE 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SAL_USING_POSIX
|
|
|
|
#ifdef FD_SETSIZE
|
|
|
|
#undef FD_SETSIZE
|
|
|
|
#endif
|
|
|
|
#define FD_SETSIZE DFS_FD_MAX
|
|
|
|
#endif /* SAL_USING_POSIX */
|
|
|
|
|
|
|
|
typedef long fd_mask;
|
|
|
|
|
2021-12-23 08:21:52 +08:00
|
|
|
#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
|
2021-10-14 00:57:32 +08:00
|
|
|
#define NBBY 8 /* number of bits in a byte */
|
2021-07-21 01:43:48 +08:00
|
|
|
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
|
|
|
|
#ifndef howmany
|
|
|
|
#define howmany(x,y) (((x)+((y)-1))/(y))
|
2021-12-23 08:21:52 +08:00
|
|
|
#endif /* howmany */
|
2021-07-21 01:43:48 +08:00
|
|
|
|
|
|
|
typedef struct _types_fd_set {
|
|
|
|
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
|
|
|
|
} _types_fd_set;
|
|
|
|
#define fd_set _types_fd_set
|
|
|
|
|
|
|
|
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
|
|
|
|
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
|
|
|
|
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
|
2023-12-28 14:26:19 +08:00
|
|
|
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
|
2021-07-21 01:43:48 +08:00
|
|
|
#endif /* _SYS_TYPES_FD_SET */
|
|
|
|
|
2021-09-14 01:07:02 +08:00
|
|
|
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
|
|
|
|
2022-04-02 16:21:45 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-21 01:43:48 +08:00
|
|
|
#endif /* __SYS_SELECT_H__ */
|