Commit eb84784c authored by Marek Vavruša's avatar Marek Vavruša Committed by Grigorii Demidov

network: make TCP_BACKLOG_DEFAULT a compile time define and set to default

This was previously hardcoded to 16. This makes it at least a compile time
define, with a default of 511 (as that's what Redis and Apache use).
parent caa205f3
Pipeline #42213 failed with stages
in 30 minutes and 1 second
......@@ -53,6 +53,12 @@
#define lua_rawlen(L, obj) lua_objlen((L), (obj))
#endif
/**@internal Maximum number of incomplete TCP connections in queue.
* Default is from Redis and Apache. */
#ifndef TCP_BACKLOG_DEFAULT
#define TCP_BACKLOG_DEFAULT 511
#endif
/** @internal Annotate for static checkers. */
KR_NORETURN int lua_error (lua_State *L);
......@@ -748,7 +754,7 @@ int engine_init(struct engine *engine, knot_mm_t *pool)
return ret;
}
/* Initialize network */
network_init(&engine->net, uv_default_loop());
network_init(&engine->net, uv_default_loop(), TCP_BACKLOG_DEFAULT);
return ret;
}
......
......@@ -347,7 +347,7 @@ static int tcp_bind_finalize(uv_handle_t *handle)
return 0;
}
static int _tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, uv_connection_cb connection)
static int _tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, uv_connection_cb connection, int tcp_backlog)
{
unsigned flags = 0;
if (addr->sa_family == AF_INET6) {
......@@ -366,7 +366,7 @@ static int _tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, uv_connection_cb c
}
#endif
ret = uv_listen((uv_stream_t *)handle, 16, connection);
ret = uv_listen((uv_stream_t *)handle, tcp_backlog, connection);
if (ret != 0) {
return ret;
}
......@@ -374,17 +374,17 @@ static int _tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, uv_connection_cb c
return tcp_bind_finalize((uv_handle_t *)handle);
}
int tcp_bind(uv_tcp_t *handle, struct sockaddr *addr)
int tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, int tcp_backlog)
{
return _tcp_bind(handle, addr, tcp_accept);
return _tcp_bind(handle, addr, tcp_accept, tcp_backlog);
}
int tcp_bind_tls(uv_tcp_t *handle, struct sockaddr *addr)
int tcp_bind_tls(uv_tcp_t *handle, struct sockaddr *addr, int tcp_backlog)
{
return _tcp_bind(handle, addr, tls_accept);
return _tcp_bind(handle, addr, tls_accept, tcp_backlog);
}
static int _tcp_bindfd(uv_tcp_t *handle, int fd, uv_connection_cb connection)
static int _tcp_bindfd(uv_tcp_t *handle, int fd, uv_connection_cb connection, int tcp_backlog)
{
if (!handle) {
return kr_error(EINVAL);
......@@ -395,21 +395,21 @@ static int _tcp_bindfd(uv_tcp_t *handle, int fd, uv_connection_cb connection)
return ret;
}
ret = uv_listen((uv_stream_t *)handle, 16, connection);
ret = uv_listen((uv_stream_t *)handle, tcp_backlog, connection);
if (ret != 0) {
return ret;
}
return tcp_bind_finalize((uv_handle_t *)handle);
}
int tcp_bindfd(uv_tcp_t *handle, int fd)
int tcp_bindfd(uv_tcp_t *handle, int fd, int tcp_backlog)
{
return _tcp_bindfd(handle, fd, tcp_accept);
return _tcp_bindfd(handle, fd, tcp_accept, tcp_backlog);
}
int tcp_bindfd_tls(uv_tcp_t *handle, int fd)
int tcp_bindfd_tls(uv_tcp_t *handle, int fd, int tcp_backlog)
{
return _tcp_bindfd(handle, fd, tls_accept);
return _tcp_bindfd(handle, fd, tls_accept, tcp_backlog);
}
int io_create(uv_loop_t *loop, uv_handle_t *handle, int type, unsigned family)
......
......@@ -27,10 +27,10 @@ struct tls_client_ctx_t;
int udp_bind(uv_udp_t *handle, struct sockaddr *addr);
int udp_bindfd(uv_udp_t *handle, int fd);
int tcp_bind(uv_tcp_t *handle, struct sockaddr *addr);
int tcp_bind_tls(uv_tcp_t *handle, struct sockaddr *addr);
int tcp_bindfd(uv_tcp_t *handle, int fd);
int tcp_bindfd_tls(uv_tcp_t *handle, int fd);
int tcp_bind(uv_tcp_t *handle, struct sockaddr *addr, int tcp_backlog);
int tcp_bind_tls(uv_tcp_t *handle, struct sockaddr *addr, int tcp_backlog);
int tcp_bindfd(uv_tcp_t *handle, int fd, int tcp_backlog);
int tcp_bindfd_tls(uv_tcp_t *handle, int fd, int tcp_backlog);
void tcp_timeout_trigger(uv_timer_t *timer);
/** Initialize the handle, incl. ->data = struct session * instance.
......
......@@ -46,7 +46,7 @@
uv_ ## type ## _init((loop), (handle))
#endif
void network_init(struct network *net, uv_loop_t *loop)
void network_init(struct network *net, uv_loop_t *loop, int tcp_backlog)
{
if (net != NULL) {
net->loop = loop;
......@@ -56,6 +56,7 @@ void network_init(struct network *net, uv_loop_t *loop)
tls_session_ticket_ctx_create(loop, NULL, 0);
net->tcp.in_idle_timeout = 10000;
net->tcp.tls_handshake_timeout = TLS_MAX_HANDSHAKE_TIME;
net->tcp_backlog = tcp_backlog;
}
}
......@@ -166,10 +167,10 @@ static int open_endpoint(struct network *net, struct endpoint *ep, struct sockad
memset(ep->tcp, 0, sizeof(*ep->tcp));
handle_init(tcp, net->loop, ep->tcp, sa->sa_family); /* can return! */
if (flags & NET_TLS) {
ret = tcp_bind_tls(ep->tcp, sa);
ret = tcp_bind_tls(ep->tcp, sa, net->tcp_backlog);
ep->flags |= NET_TLS;
} else {
ret = tcp_bind(ep->tcp, sa);
ret = tcp_bind(ep->tcp, sa, net->tcp_backlog);
}
if (ret != 0) {
return ret;
......@@ -213,10 +214,10 @@ static int open_endpoint_fd(struct network *net, struct endpoint *ep, int fd, in
}
uv_tcp_init(net->loop, ep->tcp);
if (use_tls) {
ret = tcp_bindfd_tls(ep->tcp, fd);
ret = tcp_bindfd_tls(ep->tcp, fd, net->tcp_backlog);
ep->flags |= NET_TLS;
} else {
ret = tcp_bindfd(ep->tcp, fd);
ret = tcp_bindfd(ep->tcp, fd, net->tcp_backlog);
}
if (ret != 0) {
close_handle((uv_handle_t *)ep->tcp, false);
......
......@@ -55,9 +55,10 @@ struct network {
map_t tls_client_params;
struct tls_session_ticket_ctx *tls_session_ticket_ctx;
struct net_tcp_param tcp;
int tcp_backlog;
};
void network_init(struct network *net, uv_loop_t *loop);
void network_init(struct network *net, uv_loop_t *loop, int tcp_backlog);
void network_deinit(struct network *net);
int network_listen_fd(struct network *net, int fd, bool use_tls);
int network_listen(struct network *net, const char *addr, uint16_t port, uint32_t flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment