Browse code

- set socket options to TOS low delay - REUSEADDR is now on by default for tcp

Andrei Pelinescu-Onciul authored on 14/04/2003 19:27:57
Showing 2 changed files
... ...
@@ -38,6 +38,7 @@
38 38
  *  2003-03-31  always try to find the corresponding tcp listen socket for
39 39
  *               a temp. socket and store in in *->bind_address: added
40 40
  *               find_tcp_si, modified tcpconn_connect (andrei)
41
+ *  2003-04-14  set sockopts to TOS low delay (andrei)
41 42
  */
42 43
 
43 44
 
... ...
@@ -53,6 +54,7 @@
53 53
 #include <sys/types.h>
54 54
 #include <sys/select.h>
55 55
 #include <sys/socket.h>
56
+#include <netinet/ip.h>
56 57
 #include <netinet/tcp.h>
57 58
 #include <sys/uio.h>  /* writev*/
58 59
 #include <netdb.h>
... ...
@@ -174,6 +176,7 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
174 174
 	struct socket_info* si;
175 175
 	union sockaddr_union my_name;
176 176
 	int my_name_len;
177
+	int optval;
177 178
 #ifdef DISABLE_NAGLE
178 179
 	int flag;
179 180
 #endif
... ...
@@ -186,16 +189,20 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
186 186
 	}
187 187
 #ifdef DISABLE_NAGLE
188 188
 	flag=1;
189
-	if ( (tcp_proto_no!=-1) && 
190
-/* fix:	I used to get here 
191
- * ERROR: tcp_connect: could not disable Nagle: Protocol not available	  
192
- * 			(setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY, */
193
-			  (setsockopt(s, tcp_proto_no , TCP_NODELAY,
189
+	if ( (tcp_proto_no!=-1) && (setsockopt(s, tcp_proto_no , TCP_NODELAY,
194 190
 					&flag, sizeof(flag))<0) ){
195 191
 		LOG(L_ERR, "ERROR: tcp_connect: could not disable Nagle: %s\n",
196 192
 				strerror(errno));
197 193
 	}
198 194
 #endif
195
+	/* tos*/
196
+	optval=IPTOS_LOWDELAY;
197
+	if (setsockopt(s, IPPROTO_IP, IP_TOS, (void*)&optval, sizeof(optval)) ==-1){
198
+		LOG(L_WARN, "WARNING: tcpconn_connect: setsockopt tos: %s\n",
199
+				strerror(errno));
200
+		/* continue since this is not critical */
201
+	}
202
+
199 203
 	if (connect(s, &server->s, sockaddru_len(*server))<0){
200 204
 		LOG(L_ERR, "ERROR: tcpconn_connect: connect: (%d) %s\n",
201 205
 				errno, strerror(errno));
... ...
@@ -491,9 +498,7 @@ void tcpconn_timeout(fd_set* set)
491 491
 int tcp_init(struct socket_info* sock_info)
492 492
 {
493 493
 	union sockaddr_union* addr;
494
-#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR) 
495 494
 	int optval;
496
-#endif
497 495
 #ifdef DISABLE_NAGLE
498 496
 	int flag;
499 497
 	struct protoent* pe;
... ...
@@ -531,7 +536,7 @@ int tcp_init(struct socket_info* sock_info)
531 531
 #endif
532 532
 
533 533
 
534
-#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR) 
534
+#if  !defined(TCP_DONT_REUSEADDR) 
535 535
 	/* Stevens, "Network Programming", Section 7.5, "Generic Socket
536 536
      * Options": "...server started,..a child continues..on existing
537 537
 	 * connection..listening server is restarted...call to bind fails
... ...
@@ -549,7 +554,13 @@ int tcp_init(struct socket_info* sock_info)
549 549
 		goto error;
550 550
 	}
551 551
 #endif
552
-
552
+	/* tos */
553
+	optval=IPTOS_LOWDELAY;
554
+	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
555
+				sizeof(optval)) ==-1){
556
+		LOG(L_WARN, "WARNING: tcp_init: setsockopt tos: %s\n", strerror(errno));
557
+		/* continue since this is not critical */
558
+	}
553 559
 	if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){
554 560
 		LOG(L_ERR, "ERROR: tcp_init: bind(%x, %p, %d) on %s: %s\n",
555 561
 				sock_info->socket, &addr->s, 
... ...
@@ -29,6 +29,7 @@
29 29
  *  2003-01-28  packet zero-termination moved to receive_msg (jiri)
30 30
  *  2003-02-10  undoed the above changes (andrei)
31 31
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
32
+ *  2003-04-14  set sockopts to TOS low delay (andrei)
32 33
  */
33 34
 
34 35
 
... ...
@@ -37,6 +38,7 @@
37 37
 #include <sys/types.h>
38 38
 #include <sys/socket.h>
39 39
 #include <netinet/in.h>
40
+#include <netinet/ip.h>
40 41
 #include <errno.h>
41 42
 #include <arpa/inet.h>
42 43
 #ifdef __linux__
... ...
@@ -234,6 +236,13 @@ int udp_init(struct socket_info* sock_info)
234 234
 		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
235 235
 		goto error;
236 236
 	}
237
+	/* tos */
238
+	optval=IPTOS_LOWDELAY;
239
+	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
240
+			sizeof(optval)) ==-1){
241
+		LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n", strerror(errno));
242
+		/* continue since this is not critical */
243
+	}
237 244
 #if defined (__linux__) && defined(UDP_ERRORS)
238 245
 	optval=1;
239 246
 	/* enable error receiving on unconnected sockets */