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(); ...@@ -91,6 +91,9 @@ std::pair<native_socket, native_socket> create_pipe();
/// throws `network_error` on error /// throws `network_error` on error
expected<void> child_process_inherit(native_socket fd, bool new_value); 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` /// Sets fd to nonblocking if `set_nonblocking == true`
/// or to blocking if `set_nonblocking == false` /// or to blocking if `set_nonblocking == false`
/// throws `network_error` on error /// throws `network_error` on error
......
...@@ -672,6 +672,7 @@ void default_multiplexer::exec_later(resumable* ptr) { ...@@ -672,6 +672,7 @@ void default_multiplexer::exec_later(resumable* ptr) {
scribe_ptr default_multiplexer::new_scribe(native_socket fd) { scribe_ptr default_multiplexer::new_scribe(native_socket fd) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
keepalive(fd, true);
return make_counted<scribe_impl>(*this, fd); return make_counted<scribe_impl>(*this, fd);
} }
......
...@@ -139,6 +139,15 @@ namespace network { ...@@ -139,6 +139,15 @@ namespace network {
CALL_CFUN(set_res, detail::cc_not_minus1, "fcntl", fcntl(fd, F_SETFD, wf)); CALL_CFUN(set_res, detail::cc_not_minus1, "fcntl", fcntl(fd, F_SETFD, wf));
return unit; 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) { expected<void> nonblocking(native_socket fd, bool new_value) {
CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value)); CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value));
...@@ -222,6 +231,15 @@ namespace network { ...@@ -222,6 +231,15 @@ namespace network {
// nop; FIXME: possible to implement via SetHandleInformation ? // nop; FIXME: possible to implement via SetHandleInformation ?
return unit; 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) { expected<void> nonblocking(native_socket fd, bool new_value) {
u_long mode = new_value ? 1 : 0; u_long mode = new_value ? 1 : 0;
......
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