diff --git a/configure.ac b/configure.ac index 8bb9bc7..d5d2d60 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ AC_PROG_CC AM_PROG_VALAC([0.7.0]) AC_PROG_INSTALL -AC_SUBST(MCONNECT_VALAFLAGS, ["--pkg=json-glib-1.0 --pkg=gee-0.8 --pkg=libnotify"]) +AC_SUBST(MCONNECT_VALAFLAGS, ["--pkg=json-glib-1.0 --pkg=gee-0.8 --pkg=libnotify --pkg=posix"]) # AC_SUBST(MCONNECT_VALAFLAGS, [--pkg=json-glib-1.0 --pkg=gee-0.8]) PKG_CHECK_MODULES(MCONNECT, [glib-2.0, gobject-2.0, diff --git a/src/devicechannel.vala b/src/devicechannel.vala index 812de01..81fee47 100644 --- a/src/devicechannel.vala +++ b/src/devicechannel.vala @@ -19,6 +19,7 @@ */ using MConn; +using Posix; /** * Device communication channel @@ -49,7 +50,7 @@ class DeviceChannel : Object { } public async bool open() { - assert(this._isa != null); + GLib.assert(this._isa != null); debug("connect to %s:%u", _isa.address.to_string(), _isa.port); @@ -75,6 +76,35 @@ class DeviceChannel : Object { // setup socket monitoring Socket sock = _conn.get_socket(); + +#if 0 + IPPROTO_TCP = 6, /* Transmission Control Protocol. */ + + TCP_KEEPIDLE 4 /* Start keeplives after this period */ + TCP_KEEPINTVL 5 /* Interval between keepalives */ + TCP_KEEPCNT 6 /* Number of keepalives before death */ +#endif +#if 0 + int option = 10; + Posix.setsockopt(sock.fd, 6, 4, &option, (Posix.socklen_t) sizeof(int)); + option = 5; + Posix.setsockopt(sock.fd, 6, 5, &option, (Posix.socklen_t) sizeof(int)); + option = 3; + Posix.setsockopt(sock.fd, 6, 6, &option, (Posix.socklen_t) sizeof(int)); +#endif + int option = 10; + Posix.setsockopt(sock.fd, IPProto.TCP, + Posix.TCP_KEEPIDLE, + &option, (Posix.socklen_t) sizeof(int)); + option = 5; + Posix.setsockopt(sock.fd, IPProto.TCP, + Posix.TCP_KEEPINTVL, + &option, (Posix.socklen_t) sizeof(int)); + option = 3; + Posix.setsockopt(sock.fd, IPProto.TCP, + Posix.TCP_KEEPCNT, + &option, (Posix.socklen_t) sizeof(int)); + // enable keepalive sock.set_keepalive(true); // prep source for monitoring events