Browse code

tcpops: set tcp keepalive values when available per option

- cover macos and *bsd for couple of options

(cherry picked from commit 278fd5a892c14f23e9f2b8d1f3fd3232c1d319f3)
(cherry picked from commit eb5f2096282e93b14fecfc64f22aba0db467dec5)
(cherry picked from commit 37f847af805ec20762348898c6427c8df8d02025)

Daniel-Constantin Mierla authored on 29/03/2019 09:06:28
Showing 1 changed files
... ...
@@ -105,8 +105,13 @@ error_release:
105 105
 	return 0;
106 106
 }
107 107
 
108
-#if !defined(HAVE_SO_KEEPALIVE) || !defined(HAVE_TCP_KEEPIDLE) || !defined(HAVE_TCP_KEEPCNT) || !defined(HAVE_TCP_KEEPINTVL)
109
-	#warning "TCP keepalive is not fully supported by your platform"
108
+#if !defined(HAVE_SO_KEEPALIVE) || !defined(HAVE_TCP_KEEPCNT) || !defined(HAVE_TCP_KEEPINTVL)
109
+	#define KSR_TCPOPS_NOKEEPALIVE
110
+#endif
111
+
112
+#ifdef KSR_TCPOPS_NOKEEPALIVE
113
+
114
+#warning "TCP keepalive options not supported by this platform"
110 115
 
111 116
 int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int closefd)
112 117
 {
... ...
@@ -119,6 +124,7 @@ int tcpops_keepalive_disable(int fd, int closefd)
119 124
 	LM_ERR("tcp_keepalive_disable() failed: this module does not support your platform\n");
120 125
 	return -1;
121 126
 }
127
+
122 128
 #else
123 129
 
124 130
 int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int closefd)
... ...
@@ -131,11 +137,15 @@ int tcpops_keepalive_enable(int fd, int idle, int count, int interval, int close
131 137
 		LM_ERR("failed to enable SO_KEEPALIVE: %s\n", strerror(errno));
132 138
 		return -1;
133 139
 	} else {
134
-
140
+#ifdef HAVE_TCP_KEEPIDLE
135 141
 		if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle,
136 142
 						sizeof(idle))<0){
137 143
 			LM_ERR("failed to set keepalive idle interval: %s\n", strerror(errno));
138 144
 		}
145
+#else
146
+		#warning "TCP_KEEPIDLE option not supported by this platform"
147
+		LM_DBG("TCP_KEEPIDLE option not available - ignoring\n");
148
+#endif
139 149
 
140 150
 		if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &count,
141 151
 						sizeof(count))<0){