Skip to content

Commit

Permalink
Fixes sys/select.h when the SDK does not define fd_set.
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsracz committed Feb 11, 2018
1 parent 2906c73 commit 78becaf
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion include/esp8266/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,53 @@
#ifndef _SYS_SELECT_H_
#define _SYS_SELECT_H_

/* We can actually pull the FD Set macros from here */
/* We can actually pull the FD Set macros from here, but sometimes that won't
* work. */
#include <sys/types.h>
#include <sys/time.h>

#ifdef __cplusplus
extern "C" {


#ifndef _SYS_TYPES_FD_SET
# define _SYS_TYPES_FD_SET
# define NBBY 8 /* number of bits in a byte */
/*
* Select uses bit masks of file descriptors in longs.
* These macros manipulate such bit fields (the filesystem macros use chars).
* FD_SETSIZE may be defined by the user, but the default here
* should be >= NOFILE (param.h).
*/
# ifndef FD_SETSIZE
# define FD_SETSIZE 64
# endif

typedef long fd_mask;
# define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
# ifndef howmany
# define howmany(x,y) (((x)+((y)-1))/(y))
# endif

/* We use a macro for fd_set so that including Sockets.h afterwards
can work. */
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)))
# define FD_ZERO(p) (__extension__ (void)({ \
size_t __i; \
char *__tmp = (char *)p; \
for (__i = 0; __i < sizeof (*(p)); ++__i) \
*__tmp++ = 0; \
}))
#endif // fd_set

#endif

/** POSIX select().
Expand Down

0 comments on commit 78becaf

Please sign in to comment.