|
@ -506,9 +506,19 @@ connect_to_remote(EV_P_ struct addrinfo *res, |
|
|
|
|
|
|
|
|
remote_t *remote = new_remote(sockfd); |
|
|
remote_t *remote = new_remote(sockfd); |
|
|
|
|
|
|
|
|
#ifdef TCP_FASTOPEN |
|
|
|
|
|
if (fast_open) { |
|
|
if (fast_open) { |
|
|
#ifdef __APPLE__ |
|
|
|
|
|
|
|
|
#if defined(TCP_FASTOPEN_CONNECT) |
|
|
|
|
|
int optval = 1; |
|
|
|
|
|
if(setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, |
|
|
|
|
|
(void *)&optval, sizeof(optval)) < 0) |
|
|
|
|
|
FATAL("failed to set TCP_FASTOPEN_CONNECT"); |
|
|
|
|
|
int s = connect(sockfd, res->ai_addr, res->ai_addrlen); |
|
|
|
|
|
if (s == 0) |
|
|
|
|
|
s = send(sockfd, server->buf->data, server->buf->len, 0); |
|
|
|
|
|
#elif defined(MSG_FASTOPEN) |
|
|
|
|
|
ssize_t s = sendto(sockfd, server->buf->data, server->buf->len, |
|
|
|
|
|
MSG_FASTOPEN, res->ai_addr, res->ai_addrlen); |
|
|
|
|
|
#elif defined(CONNECT_DATA_IDEMPOTENT) |
|
|
((struct sockaddr_in *)(res->ai_addr))->sin_len = sizeof(struct sockaddr_in); |
|
|
((struct sockaddr_in *)(res->ai_addr))->sin_len = sizeof(struct sockaddr_in); |
|
|
sa_endpoints_t endpoints; |
|
|
sa_endpoints_t endpoints; |
|
|
memset((char *)&endpoints, 0, sizeof(endpoints)); |
|
|
memset((char *)&endpoints, 0, sizeof(endpoints)); |
|
@ -521,16 +531,13 @@ connect_to_remote(EV_P_ struct addrinfo *res, |
|
|
size_t len; |
|
|
size_t len; |
|
|
int s = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY, CONNECT_DATA_IDEMPOTENT, |
|
|
int s = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY, CONNECT_DATA_IDEMPOTENT, |
|
|
&iov, 1, &len, NULL); |
|
|
&iov, 1, &len, NULL); |
|
|
if (s == 0) { |
|
|
|
|
|
|
|
|
if (s == 0) |
|
|
s = len; |
|
|
s = len; |
|
|
} |
|
|
|
|
|
#else |
|
|
#else |
|
|
ssize_t s = sendto(sockfd, server->buf->data, server->buf->len, |
|
|
|
|
|
MSG_FASTOPEN, res->ai_addr, res->ai_addrlen); |
|
|
|
|
|
|
|
|
FATAL("fast open is not enabled in this build"); |
|
|
#endif |
|
|
#endif |
|
|
if (s == -1) { |
|
|
if (s == -1) { |
|
|
if (errno == CONNECT_IN_PROGRESS || errno == EAGAIN |
|
|
|
|
|
|| errno == EWOULDBLOCK) { |
|
|
|
|
|
|
|
|
if (errno == CONNECT_IN_PROGRESS) { |
|
|
// The remote server doesn't support tfo or it's the first connection to the server. |
|
|
// The remote server doesn't support tfo or it's the first connection to the server. |
|
|
// It will automatically fall back to conventional TCP. |
|
|
// It will automatically fall back to conventional TCP. |
|
|
} else if (errno == EOPNOTSUPP || errno == EPROTONOSUPPORT || |
|
|
} else if (errno == EOPNOTSUPP || errno == EPROTONOSUPPORT || |
|
@ -546,7 +553,6 @@ connect_to_remote(EV_P_ struct addrinfo *res, |
|
|
server->buf->len -= s; |
|
|
server->buf->len -= s; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (!fast_open) { |
|
|
if (!fast_open) { |
|
|
int r = connect(sockfd, res->ai_addr, res->ai_addrlen); |
|
|
int r = connect(sockfd, res->ai_addr, res->ai_addrlen); |
|
|