-/*!
- * Connect with TCP Fast Open.
- */
-static int fastopen_connect(int sockfd, const struct addrinfo *srv)
-{
-#if defined( __FreeBSD__)
- const int enable = 1;
- return setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN, &enable, sizeof(enable));
-#elif defined(__APPLE__)
- // connection is performed lazily when first data are sent
- struct sa_endpoints ep = {0};
- ep.sae_dstaddr = srv->ai_addr;
- ep.sae_dstaddrlen = srv->ai_addrlen;
- int flags = CONNECT_DATA_IDEMPOTENT|CONNECT_RESUME_ON_READ_WRITE;
-
- return connectx(sockfd, &ep, SAE_ASSOCID_ANY, flags, NULL, 0, NULL, NULL);
-#elif defined(__linux__)
- // connect() will be called implicitly with sendto(), sendmsg()
- return 0;
-#else
- errno = ENOTSUP;
- return -1;
-#endif
-}
-
-/*!
- * Sends data with TCP Fast Open.
- */
-static int fastopen_send(int sockfd, const struct msghdr *msg, int timeout)
-{
-#if defined(__FreeBSD__) || defined(__APPLE__)
- return sendmsg(sockfd, msg, 0);
-#elif defined(__linux__)
- int ret = sendmsg(sockfd, msg, MSG_FASTOPEN);
- if (ret == -1 && errno == EINPROGRESS) {
- struct pollfd pfd = {
- .fd = sockfd,
- .events = POLLOUT,
- .revents = 0,
- };
- if (poll(&pfd, 1, 1000 * timeout) != 1) {
- errno = ETIMEDOUT;
- return -1;
- }
- ret = sendmsg(sockfd, msg, 0);
- }
- return ret;
-#else
- errno = ENOTSUP;
- return -1;
-#endif
-}
-