jeremycw / httpserver.h

Single header library for writing non-blocking HTTP servers in C
MIT License
1.78k stars 143 forks source link

Set _DEFAULT_SOURCE to ensure SO_REUSEPORT is present #43

Open sternenseemann opened 4 years ago

sternenseemann commented 4 years ago

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 commented 4 years ago

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.