Permalink
Browse files

Merge pull request #119 from jonludlam/keepalives

CA-94829: Bindings to the TCP keepalive settings
  • Loading branch information...
2 parents ad02a87 + 5cc440a commit 5ff0d5e97a010894610a410a9143b00cf865919b @jonludlam jonludlam committed Jan 21, 2013
Showing with 28 additions and 1 deletion.
  1. +1 −1 stdext/unixext.ml
  2. +1 −0 stdext/unixext.mli
  3. +26 −0 stdext/unixext_stubs.c
View
@@ -559,7 +559,7 @@ let double_fork f =
| pid -> ignore(Unix.waitpid [] pid)
external set_tcp_nodelay : Unix.file_descr -> bool -> unit = "stub_unixext_set_tcp_nodelay"
-
+external set_sock_keepalives : Unix.file_descr -> int -> int -> int -> unit = "stub_unixext_set_sock_keepalives"
external fsync : Unix.file_descr -> unit = "stub_unixext_fsync"
external blkgetsize64 : Unix.file_descr -> int64 = "stub_unixext_blkgetsize64"
View
@@ -118,6 +118,7 @@ val spawnvp :
val double_fork : (unit -> unit) -> unit
external set_tcp_nodelay : Unix.file_descr -> bool -> unit
= "stub_unixext_set_tcp_nodelay"
+external set_sock_keepalives : Unix.file_descr -> int -> int -> int -> unit = "stub_unixext_set_sock_keepalives"
external fsync : Unix.file_descr -> unit = "stub_unixext_fsync"
external get_max_fd : unit -> int = "stub_unixext_get_max_fd"
external blkgetsize64 : Unix.file_descr -> int64 = "stub_unixext_blkgetsize64"
View
@@ -72,6 +72,32 @@ CAMLprim value stub_unixext_get_max_fd (value unit)
CAMLreturn(Val_int(maxfd));
}
+CAMLprim value stub_unixext_set_sock_keepalives(value fd, value count, value idle, value interval)
+{
+ CAMLparam4(fd, count, idle, interval);
+
+ int c_fd = Int_val(fd);
+ int optval;
+ socklen_t optlen=sizeof(optval);
+
+ optval = Int_val(count);
+ if(setsockopt(c_fd, SOL_TCP, TCP_KEEPCNT, &optval, optlen) < 0) {
+ uerror("setsockopt(TCP_KEEPCNT)", Nothing);
+ }
+
+ optval = Int_val(idle);
+ if(setsockopt(c_fd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen) < 0) {
+ uerror("setsockopt(TCP_KEEPIDLE)", Nothing);
+ }
+
+ optval = Int_val(interval);
+ if(setsockopt(c_fd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen) < 0) {
+ uerror("setsockopt(TCP_KEEPINTVL)", Nothing);
+ }
+
+ CAMLreturn(Val_unit);
+}
+
#define FDSET_OF_VALUE(v) (&(((struct fdset_t *) v)->fds))
#define MAXFD_OF_VALUE(v) (((struct fdset_t *) v)->max)
struct fdset_t { fd_set fds; int max; };

0 comments on commit 5ff0d5e

Please sign in to comment.