Browse Source

mconnect/devicechannel, utils: move socket keepalive setup to utils

bboozzoo/dbus-support-fileshare
Maciek Borzecki 8 years ago
parent
commit
574e54aff5
2 changed files with 42 additions and 31 deletions
  1. +1
    -31
      src/mconnect/devicechannel.vala
  2. +41
    -0
      src/mconnect/utils.vala

+ 1
- 31
src/mconnect/devicechannel.vala View File

@ -19,7 +19,6 @@
*/ */
using Mconn; using Mconn;
using Posix;
/** /**
* Device communication channel * Device communication channel
@ -50,36 +49,7 @@ class DeviceChannel : Object {
} }
private static void fixup_socket(Socket sock) { 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) { private void replace_streams(InputStream input, OutputStream output) {


+ 41
- 0
src/mconnect/utils.vala View File

@ -17,6 +17,7 @@
* AUTHORS * AUTHORS
* Maciek Borzecki <maciek.borzecki (at] gmail.com> * Maciek Borzecki <maciek.borzecki (at] gmail.com>
*/ */
using Posix;
/** /**
* @array_list_to_list: * @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); 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);
}

Loading…
Cancel
Save