libfreerdp-core: set SO_KEEPALIVE socket option

This commit is contained in:
Marc-André Moreau 2011-12-11 19:51:58 -05:00
parent aec2b492e4
commit 9d1f13e82e
2 changed files with 31 additions and 0 deletions

View File

@ -167,6 +167,8 @@ boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port)
}
}
tcp_set_keep_alive_mode(tcp);
return true;
}
@ -258,6 +260,34 @@ boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking)
return true;
}
boolean tcp_set_keep_alive_mode(rdpTcp* tcp)
{
#ifndef _WIN32
uint32 option_value;
socklen_t option_len;
option_value = 1;
option_len = sizeof(option_value);
if (setsockopt(tcp->sockfd, SOL_SOCKET, SO_KEEPALIVE, (void*) &option_value, option_len) < 0)
{
perror("setsockopt() SOL_SOCKET, SO_KEEPALIVE:");
return false;
}
option_value = 5;
option_len = sizeof(option_value);
if (setsockopt(tcp->sockfd, SOL_TCP, TCP_KEEPIDLE, (void*) &option_value, option_len) < 0)
{
perror("setsockopt() SOL_TCP, SO_KEEPIDLE:");
return false;
}
#endif
return true;
}
rdpTcp* tcp_new(rdpSettings* settings)
{
rdpTcp* tcp;

View File

@ -53,6 +53,7 @@ boolean tcp_disconnect(rdpTcp* tcp);
int tcp_read(rdpTcp* tcp, uint8* data, int length);
int tcp_write(rdpTcp* tcp, uint8* data, int length);
boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking);
boolean tcp_set_keep_alive_mode(rdpTcp* tcp);
rdpTcp* tcp_new(rdpSettings* settings);
void tcp_free(rdpTcp* tcp);