Add support for TCP_FASTOPEN_CONNECT
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include <netinet/ip.h>
|
#include <netinet/ip.h>
|
||||||
#include <netinet/ip6.h>
|
#include <netinet/ip6.h>
|
||||||
#include <netinet/ip_icmp.h>
|
#include <netinet/ip_icmp.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -50,6 +51,10 @@
|
|||||||
#define DNS_HOSTNAME_LEN 128
|
#define DNS_HOSTNAME_LEN 128
|
||||||
#define DNS_TCP_BUFFER (16 * 1024)
|
#define DNS_TCP_BUFFER (16 * 1024)
|
||||||
|
|
||||||
|
#ifndef TCP_FASTOPEN_CONNECT
|
||||||
|
#define TCP_FASTOPEN_CONNECT 30
|
||||||
|
#endif
|
||||||
|
|
||||||
struct dns_client_ecs {
|
struct dns_client_ecs {
|
||||||
int enable;
|
int enable;
|
||||||
unsigned int family;
|
unsigned int family;
|
||||||
@@ -739,6 +744,7 @@ static int _DNS_client_create_socket_tcp(struct dns_server_info *server_info)
|
|||||||
{
|
{
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
struct epoll_event event;
|
struct epoll_event event;
|
||||||
|
int yes = 1;
|
||||||
|
|
||||||
fd = socket(server_info->ai_family, SOCK_STREAM, 0);
|
fd = socket(server_info->ai_family, SOCK_STREAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@@ -751,6 +757,10 @@ static int _DNS_client_create_socket_tcp(struct dns_server_info *server_info)
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &yes, sizeof(yes)) != 0 ) {
|
||||||
|
tlog(TLOG_DEBUG, "enable TCP fast open failed.");
|
||||||
|
}
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
||||||
if (errno != EINPROGRESS) {
|
if (errno != EINPROGRESS) {
|
||||||
tlog(TLOG_ERROR, "connect failed.");
|
tlog(TLOG_ERROR, "connect failed.");
|
||||||
@@ -784,6 +794,7 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info)
|
|||||||
struct epoll_event event;
|
struct epoll_event event;
|
||||||
SSL_CTX *ctx = NULL;
|
SSL_CTX *ctx = NULL;
|
||||||
SSL *ssl = NULL;
|
SSL *ssl = NULL;
|
||||||
|
int yes = 1;
|
||||||
|
|
||||||
ctx = SSL_CTX_new(SSLv23_client_method());
|
ctx = SSL_CTX_new(SSLv23_client_method());
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
@@ -808,6 +819,10 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info)
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &yes, sizeof(yes)) != 0 ) {
|
||||||
|
tlog(TLOG_DEBUG, "enable TCP fast open failed.");
|
||||||
|
}
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
||||||
if (errno != EINPROGRESS) {
|
if (errno != EINPROGRESS) {
|
||||||
tlog(TLOG_ERROR, "connect failed.");
|
tlog(TLOG_ERROR, "connect failed.");
|
||||||
|
|||||||
Reference in New Issue
Block a user