httpserver.h icon indicating copy to clipboard operation
httpserver.h copied to clipboard

Set _DEFAULT_SOURCE to ensure SO_REUSEPORT is present

Open sternenseemann opened this issue 5 years ago • 1 comments

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.

sternenseemann avatar Sep 13 '20 11:09 sternenseemann

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.

sternenseemann avatar Sep 14 '20 10:09 sternenseemann