httpserver.h
httpserver.h copied to clipboard
Set _DEFAULT_SOURCE to ensure SO_REUSEPORT is present
This resolves an issue with glibc 2.31 I experienced where SO_REUSEPORT would be missing because glibc only includes linux headers if __USE_MISC is set which is caused by _DEFAULT_SOURCE in features.h.
To be precise test/main.c wouldn't compile on NixOS with glibc 2.31.
Adding -D_DEFAULT_SOURCE to CFLAGS also resolves the issue. Below is the offending bits/socket.h snippet for glibc 2.31 as found on my system. I'm actually not sure if this may be just a NixOS-specific oddity.
#ifdef __USE_MISC
# include <bits/types/time_t.h>
# include <asm/socket.h>
#else
# define SO_DEBUG 1
# include <bits/socket-constants.h>
#endif
asm/socket.h defines SO_REUSEPORT (it includes something from linux-headers), but bits/socket-constants.h does not.