diff options
author | Tim Rühsen <tim.ruehsen@gmx.de> | 2017-04-10 12:39:46 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-04-11 19:34:49 +0300 |
commit | c99d46b13c32027a49b9991ba525ad01b8a3da62 (patch) | |
tree | f15e3120bd5fb38aece337a57dd28144fa5e1469 /lib/system | |
parent | 5dc86ac812a8bd73a5e05c4d7ebba113fe921835 (diff) | |
download | gnutls-c99d46b13c32027a49b9991ba525ad01b8a3da62.tar.gz |
lib/system/fastopen: Add TCP Fast Open for OSXtmp-fast-open-macosx
Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/fastopen.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/system/fastopen.c b/lib/system/fastopen.c index 146e8ec6e8..b2310dda49 100644 --- a/lib/system/fastopen.c +++ b/lib/system/fastopen.c @@ -35,6 +35,13 @@ # include <netinet/tcp.h> #endif +/* 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 +#elif defined TCP_FASTOPEN && defined MSG_FASTOPEN +# define TCP_FASTOPEN_LINUX +#endif + /* Do not use the gnulib functions for sending and receiving data. * Using them makes gnutls only working with gnulib applications. */ @@ -85,7 +92,7 @@ tfo_writev(gnutls_transport_ptr_t ptr, const giovec_t * iovec, int iovec_cnt) if (likely(!p->connect_addrlen)) return sendmsg(fd, &hdr, p->flags); -#ifdef MSG_FASTOPEN +#ifdef TCP_FASTOPEN_LINUX if (!p->connect_only) { if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &on, sizeof(on)) == -1) _gnutls_debug_log("Failed to set socket option FASTOPEN\n"); @@ -110,7 +117,12 @@ tfo_writev(gnutls_transport_ptr_t ptr, const giovec_t * iovec, int iovec_cnt) #endif { connect_only: +#ifdef TCP_FASTOPEN_OSX + 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); +#else ret = connect(fd, (struct sockaddr*)&p->connect_addr, p->connect_addrlen); +#endif if (errno == ENOTCONN || errno == EINPROGRESS) { gnutls_assert(); errno = EAGAIN; |