Commit c83b660c authored by Joseph Noir's avatar Joseph Noir

Set SO_KEEPALIVE on TCP connections

parent 40e7b16e
......@@ -91,6 +91,9 @@ std::pair<native_socket, native_socket> create_pipe();
/// throws `network_error` on error
expected<void> child_process_inherit(native_socket fd, bool new_value);
/// Enables keepalive on `fd`. Throws `network_error` on error.
expected<void> keepalive(native_socket fd, bool new_value);
/// Sets fd to nonblocking if `set_nonblocking == true`
/// or to blocking if `set_nonblocking == false`
/// throws `network_error` on error
......
......@@ -672,6 +672,7 @@ void default_multiplexer::exec_later(resumable* ptr) {
scribe_ptr default_multiplexer::new_scribe(native_socket fd) {
CAF_LOG_TRACE("");
keepalive(fd, true);
return make_counted<scribe_impl>(*this, fd);
}
......
......@@ -140,6 +140,15 @@ namespace network {
return unit;
}
expected<void> keepalive(native_socket fd, bool new_value) {
CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value));
int value = new_value ? 1 : 0;
CALL_CFUN(res, detail::cc_zero, "setsockopt",
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &value,
static_cast<unsigned>(sizeof(value))));
return unit;
}
expected<void> nonblocking(native_socket fd, bool new_value) {
CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value));
// read flags for fd
......@@ -223,6 +232,15 @@ namespace network {
return unit;
}
expected<void> keepalive(native_socket fd, bool new_value) {
CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value));
char = new_value ? 1 : 0;
CALL_CFUN(res, detail::cc_zero, "setsockopt",
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &value,
static_cast<int>(sizeof(value))));
return unit;
}
expected<void> nonblocking(native_socket fd, bool new_value) {
u_long mode = new_value ? 1 : 0;
CALL_CFUN(res, detail::cc_zero, "ioctlsocket",
......
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