Browse Source

devicechannel: setup TCP keepalive

Use TCP keepalive for detecting of connection goes offline in a more
reliable manner.
bboozzoo/namespace-cleanup
Maciek Borzecki 9 years ago
parent
commit
fc8a663b72
2 changed files with 32 additions and 2 deletions
  1. +1
    -1
      configure.ac
  2. +31
    -1
      src/devicechannel.vala

+ 1
- 1
configure.ac View File

@ -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,


+ 31
- 1
src/devicechannel.vala View File

@ -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


Loading…
Cancel
Save