diff --git a/src/mconnect/devicechannel.vala b/src/mconnect/devicechannel.vala index 40a9011..dd85cb7 100644 --- a/src/mconnect/devicechannel.vala +++ b/src/mconnect/devicechannel.vala @@ -19,7 +19,6 @@ */ using Mconn; -using Posix; /** * Device communication channel @@ -50,36 +49,7 @@ class DeviceChannel : Object { } private static void fixup_socket(Socket sock) { -#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); + socket_set_keepalive(sock); } private void replace_streams(InputStream input, OutputStream output) { diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index ec67d48..2f68d54 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -17,6 +17,7 @@ * AUTHORS * Maciek Borzecki */ +using Posix; /** * @array_list_to_list: @@ -83,3 +84,43 @@ string make_device_string(string id, string name, return "%s-%s-%s-%u".printf(id, name, type, pv); } + +/** + * socket_set_keepalive: + * @sock: socket + * + * Set keepalive counters on socket + */ +void socket_set_keepalive(Socket sock) { +#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); +}