History

tools/nolibc/types: make FD_SETSIZE configurable

The macro was hard-coded to 256 but it's common to see it redefined. Let's support this and make sure we always allocate enough entries for the cases where it wouldn't be multiple of 32.

Willy Tarreau committed 4 years ago

Commit 306c9fd1 parent 8cb98b31 file · +4 −2Browse files

Showing the changes to tools/include (1 of 1 file). Show all

Unified · Split

tools/include/nolibc/types.h+4−2
@@ -45,7 +45,9 @@ · 44 unmodified lines
45#define DT_SOCK 0xc45#define DT_SOCK 0xc
46 46
47/* commonly an fd_set represents 256 FDs */47/* commonly an fd_set represents 256 FDs */
48#ifndef FD_SETSIZE
48#define FD_SETSIZE 25649#define FD_SETSIZE 256
50#endif
49 51
50/* Special FD used by all the *at functions */52/* Special FD used by all the *at functions */
51#ifndef AT_FDCWD53#ifndef AT_FDCWD
@@ -72,7 +74,7 @@ · 20 unmodified lines
72 74
73/* for select() */75/* for select() */
74typedef struct {76typedef struct {
75 uint32_t fd32[FD_SETSIZE / 32];77 uint32_t fd32[(FD_SETSIZE + 31) / 32];
76} fd_set;78} fd_set;
77 79
78#define FD_CLR(fd, set) do { \80#define FD_CLR(fd, set) do { \
@@ -101,7 +103,7 @@ typedef struct { · 22 unmodified lines
101#define FD_ZERO(set) do { \103#define FD_ZERO(set) do { \
102 fd_set *__set = (set); \104 fd_set *__set = (set); \
103 int __idx; \105 int __idx; \
104 for (__idx = 0; __idx < FD_SETSIZE / 32; __idx ++) \106 for (__idx = 0; __idx < (FD_SETSIZE+31) / 32; __idx ++) \
105 __set->fd32[__idx] = 0; \107 __set->fd32[__idx] = 0; \
106 } while (0)108 } while (0)
107 109