Skip to content

Detect the availability of connectx at runtime

Steve Lhomme requested to merge robUx4/gnutls:macos-connectx into master

connectx is only available since macOS 10.11. So when compiling with a lower minimum SDK the compiler issues this error:

system/fastopen.c:134:9: error: 'connectx' is only available on macOS 10.11 or newer [-Werror,-Wunguarded-availability]
                ret = connectx(fd, &endpoints, SAE_ASSOCID_ANY, CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT, NULL, 0, NULL, NULL);
                      ^~~~~~~~
/Applications/Xcode9.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/sys/socket.h:713:5: note: 'connectx' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.7.0

With macOS compilers it's possible to detect at runtime whether an API call is present or not using __builtin_available(). So we check at runtime for connectx and use it only when available. So the same code compiled running on 10.10 will not use it and fallback to the regular connect() call. The code running on 10.11+ will use connectx as expected.

Merge request reports