return ret;
}
/* Initialize network */
- network_init(&engine->net, uv_default_loop());
+ network_init(&engine->net, uv_default_loop(), TCP_BACKLOG_DEFAULT);
return ret;
}
#ifndef MAX_PIPELINED
#define MAX_PIPELINED 100
#endif
+#ifndef TCP_BACKLOG_DEFAULT
+#define TCP_BACKLOG_DEFAULT 511 /**< Maximum number of incomplete TCP connections in queue. Default is from Redis and Apache. */
+#endif
/*
* @internal These are forward decls to allow building modules with engine but without Lua.
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) {
}
#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;
}
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);
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);
}
void io_create(uv_loop_t *loop, uv_handle_t *handle, int type)
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);
/** Initialize the handle, incl. ->data = struct session * instance. type = SOCK_* */
void io_create(uv_loop_t *loop, uv_handle_t *handle, int type);
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;
net->tls_session_ticket_ctx = /* unsync. random, by default */
tls_session_ticket_ctx_create(loop, NULL, 0);
net->tcp.in_idle_timeout = 10000;
+ net->tcp_backlog = tcp_backlog;
}
}
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;
}
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);
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);
return kr_error(ENOENT);
}
-static int select_first_ns(const char *k, void *v, void *baton)
-{
- assert(baton);
- *((const knot_dname_t **)baton) = (const knot_dname_t *)k;
- return 1;
-}
-
const knot_dname_t *kr_zonecut_find_nsname(struct kr_zonecut *cut)
{
if (!cut) {
}
const knot_dname_t *result = NULL;
- map_walk(&cut->nsset, select_first_ns, &result);
+ trie_it_t *it;
+ for (it = trie_it_begin(cut->nsset); !trie_it_finished(it); trie_it_next(it)) {
+ result = (const knot_dname_t *)trie_it_key(it, NULL);
+ break;
+ }
+ trie_it_free(it);
return result;
}
\ No newline at end of file