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

Unified · Split

tools/include/nolibc/types.h+4−2
@@ -45,7 +45,9 @@ · 44 unmodified lines
4545 #define DT_SOCK 0xc
4646
4747 /* commonly an fd_set represents 256 FDs */
48+#ifndef FD_SETSIZE
4849 #define FD_SETSIZE 256
50+#endif
4951
5052 /* Special FD used by all the *at functions */
5153 #ifndef AT_FDCWD
@@ -72,7 +74,7 @@ · 20 unmodified lines
7274
7375 /* for select() */
7476 typedef struct {
75− uint32_t fd32[FD_SETSIZE / 32];
77+ uint32_t fd32[(FD_SETSIZE + 31) / 32];
7678 } fd_set;
7779
7880 #define FD_CLR(fd, set) do { \
@@ -101,7 +103,7 @@ typedef struct { · 22 unmodified lines
101103 #define FD_ZERO(set) do { \
102104 fd_set *__set = (set); \
103105 int __idx; \
104− for (__idx = 0; __idx < FD_SETSIZE / 32; __idx ++) \
106+ for (__idx = 0; __idx < (FD_SETSIZE+31) / 32; __idx ++) \
105107 __set->fd32[__idx] = 0; \
106108 } while (0)
107109