]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
fix connectx not available on older macOS SDK
authorSteve Lhomme <robux4@ycbcr.xyz>
Mon, 22 Jun 2020 07:09:05 +0000 (09:09 +0200)
committerSteve Lhomme <robux4@ycbcr.xyz>
Thu, 2 Jul 2020 13:07:44 +0000 (15:07 +0200)
Fixes this compilation 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

The detection is the same as found in curl [1].

If HAVE_BUILTIN_AVAILABLE is not available we fallback to the code without
TCP_FASTOPEN_OSX.

The OS values match exactly the values found in
https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/socket.h

[1] https://github.com/curl/curl/commit/870d849d48a26b8eeb0d4bb1f4655367a4a191ca

Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
lib/system/fastopen.c

index 8d8409e4821677c2de1457555c6dce9ba40b0ef2..bf1ee0929f45051f38ecfc41a179a34c1e53e965 100644 (file)
@@ -38,7 +38,9 @@
 
 /* TCP Fast Open on OSX behaves differently from Linux, so define these helpers */
 #if defined __APPLE__ && defined __MACH__ && defined CONNECT_DATA_IDEMPOTENT && defined CONNECT_RESUME_ON_READ_WRITE
-# define TCP_FASTOPEN_OSX
+# if defined __has_builtin && __has_builtin(__builtin_available)
+#  define TCP_FASTOPEN_OSX
+# endif
 #elif defined TCP_FASTOPEN && defined MSG_FASTOPEN
 # define TCP_FASTOPEN_LINUX
 #endif
@@ -129,9 +131,15 @@ tfo_writev(gnutls_transport_ptr_t ptr, const giovec_t * iovec, int iovec_cnt)
        }
 # elif defined(TCP_FASTOPEN_OSX)
        {
-               sa_endpoints_t endpoints = { .sae_dstaddr = (struct sockaddr*)&p->connect_addr, .sae_dstaddrlen = p->connect_addrlen };
+               if(__builtin_available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *)) {
+                       sa_endpoints_t endpoints = { .sae_dstaddr = (struct sockaddr*)&p->connect_addr, .sae_dstaddrlen = p->connect_addrlen };
 
-               ret = connectx(fd, &endpoints, SAE_ASSOCID_ANY, CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT, NULL, 0, NULL, NULL);
+                       ret = connectx(fd, &endpoints, SAE_ASSOCID_ANY, CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT, NULL, 0, NULL, NULL);
+               }
+               else
+               {
+                       ret = connect(fd, (struct sockaddr*)&p->connect_addr, p->connect_addrlen);
+               }
                if (errno == ENOTCONN || errno == EINPROGRESS) {
                        gnutls_assert();
                        errno = EAGAIN;