Add SO_KEEPALIVE to iprop clients (slaves)
This commit is contained in:

committed by
Viktor Dukhovni

parent
54d37fdba6
commit
8fe294d0d7
@@ -53,9 +53,10 @@ connect_to_master (krb5_context context, const char *master,
|
|||||||
struct addrinfo *ai, *a;
|
struct addrinfo *ai, *a;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
int error;
|
int error;
|
||||||
|
int one = 1;
|
||||||
int s = -1;
|
int s = -1;
|
||||||
|
|
||||||
memset (&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
if (port_str == NULL) {
|
if (port_str == NULL) {
|
||||||
@@ -63,7 +64,7 @@ connect_to_master (krb5_context context, const char *master,
|
|||||||
port_str = port;
|
port_str = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = getaddrinfo (master, port_str, &hints, &ai);
|
error = getaddrinfo(master, port_str, &hints, &ai);
|
||||||
if (error) {
|
if (error) {
|
||||||
krb5_warnx(context, "Failed to get address of to %s: %s",
|
krb5_warnx(context, "Failed to get address of to %s: %s",
|
||||||
master, gai_strerror(error));
|
master, gai_strerror(error));
|
||||||
@@ -77,24 +78,27 @@ connect_to_master (krb5_context context, const char *master,
|
|||||||
if (error)
|
if (error)
|
||||||
strlcpy(node, "[unknown-addr]", sizeof(node));
|
strlcpy(node, "[unknown-addr]", sizeof(node));
|
||||||
|
|
||||||
s = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
s = socket(a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
continue;
|
continue;
|
||||||
if (connect (s, a->ai_addr, a->ai_addrlen) < 0) {
|
if (connect(s, a->ai_addr, a->ai_addrlen) < 0) {
|
||||||
krb5_warn(context, errno, "connection failed to %s[%s]",
|
krb5_warn(context, errno, "connection failed to %s[%s]",
|
||||||
master, node);
|
master, node);
|
||||||
close (s);
|
close(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
krb5_warnx(context, "connection successful "
|
krb5_warnx(context, "connection successful "
|
||||||
"to master: %s[%s]", master, node);
|
"to master: %s[%s]", master, node);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo(ai);
|
||||||
|
|
||||||
if (a == NULL)
|
if (a == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)) < 0)
|
||||||
|
krb5_warn(context, errno, "setsockopt(SO_KEEPALIVE) failed");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user