I changed the code and tested it and keep alive option is working fine for me now.
The patch is very simple as follows:
diff --git a/socket.c b/socket.c
index 2e3e1cc..ac17b4d 100644
--- a/socket.c
+++ b/socket.c
@@ -330,6 +330,19 @@ retry:
fcntl(self->socket, F_SETFL, O_NONBLOCK);
#endif
+ {
+ int optval;
+ socklen_t optlen;
+ optval=1;
+ optlen = sizeof(optval);
+
+ if(setsockopt(self->socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0)
+ {
+ SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to SO_KEEPALIVE.");
+ goto cleanup;
+ }
+ }
+
if (curadr)
{
struct sockaddr *in = (struct sockaddr *) &(self->sadr_area);