static int net_outgoing_v4(lua_State *L) { return net_outgoing(L, AF_INET); }
static int net_outgoing_v6(lua_State *L) { return net_outgoing(L, AF_INET6); }
+static int net_tcp_in_idle(lua_State *L)
+{
+ struct engine *engine = engine_luaget(L);
+ struct network *net = &engine->net;
+
+ /* Only return current idle timeout. */
+ if (lua_gettop(L) == 0) {
+ lua_pushnumber(L, net->tcp.in_idle_timeout);
+ return 1;
+ }
+
+ if ((lua_gettop(L) != 1)) {
+ lua_pushstring(L, "net.tcp_in_idle takes one parameter: (\"idle timeout\")");
+ lua_error(L);
+ }
+
+ if (lua_isnumber(L, 1)) {
+ int idle_timeout = lua_tointeger(L, 1);
+ if (idle_timeout <= 0) {
+ lua_pushstring(L, "net.tcp_in_idle parameter has to be positive number");
+ lua_error(L);
+ }
+ net->tcp.in_idle_timeout = idle_timeout;
+ } else {
+ lua_pushstring(L, "net.tcp_in_idle parameter has to be positive number");
+ lua_error(L);
+ }
+ lua_pushboolean(L, true);
+ return 1;
+}
+
int lib_net(lua_State *L)
{
static const luaL_Reg lib[] = {
{ "tls_sticket_secret_file", net_tls_sticket_secret_file },
{ "outgoing_v4", net_outgoing_v4 },
{ "outgoing_v6", net_outgoing_v6 },
+ { "tcp_in_idle", net_tcp_in_idle },
{ NULL, NULL }
};
register_lib(L, "net", lib);
return;
}
+ const struct worker_ctx *worker = (struct worker_ctx *)master->loop->data;
+ const struct engine *engine = worker->engine;
+ const struct network *net = &engine->net;
+ uint64_t idle_in_timeout = net->tcp.in_idle_timeout;
+
uint64_t timeout = KR_CONN_RTT_MAX / 2;
session->has_tls = tls;
if (tls) {
}
}
uv_timer_t *timer = &session->timeout;
- uv_timer_start(timer, tcp_timeout_trigger, timeout, timeout);
+ uv_timer_start(timer, tcp_timeout_trigger, timeout, idle_in_timeout);
io_start_read((uv_handle_t *)client);
}
net->tls_client_params = map_make(NULL);
net->tls_session_ticket_ctx = /* unsync. random, by default */
tls_session_ticket_ctx_create(loop, NULL, 0);
+ net->tcp.in_idle_timeout = 10000;
}
}
tls_client_params_free(&net->tls_client_params);
net->tls_credentials = NULL;
tls_session_ticket_ctx_destroy(net->tls_session_ticket_ctx);
+ net->tcp.in_idle_timeout = 0;
}
}
typedef array_t(struct endpoint*) endpoint_array_t;
/* @endcond */
+struct net_tcp_param {
+ uint64_t in_idle_timeout;
+};
+
struct tls_session_ticket_ctx;
struct network {
uv_loop_t *loop;
struct tls_credentials *tls_credentials;
map_t tls_client_params;
struct tls_session_ticket_ctx *tls_session_ticket_ctx;
+ struct net_tcp_param tcp;
};
void network_init(struct network *net, uv_loop_t *loop);