... | ... |
@@ -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 | 54 |
#include <sys/types.h> |
54 | 55 |
#include <sys/select.h> |
55 | 56 |
#include <sys/socket.h> |
57 |
+#include <netinet/ip.h> |
|
56 | 58 |
#include <netinet/tcp.h> |
57 | 59 |
#include <sys/uio.h> /* writev*/ |
58 | 60 |
#include <netdb.h> |
... | ... |
@@ -174,6 +176,7 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server) |
174 | 176 |
struct socket_info* si; |
175 | 177 |
union sockaddr_union my_name; |
176 | 178 |
int my_name_len; |
179 |
+ int optval; |
|
177 | 180 |
#ifdef DISABLE_NAGLE |
178 | 181 |
int flag; |
179 | 182 |
#endif |
... | ... |
@@ -186,16 +189,20 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server) |
186 | 189 |
} |
187 | 190 |
#ifdef DISABLE_NAGLE |
188 | 191 |
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, |
|
192 |
+ if ( (tcp_proto_no!=-1) && (setsockopt(s, tcp_proto_no , TCP_NODELAY, |
|
194 | 193 |
&flag, sizeof(flag))<0) ){ |
195 | 194 |
LOG(L_ERR, "ERROR: tcp_connect: could not disable Nagle: %s\n", |
196 | 195 |
strerror(errno)); |
197 | 196 |
} |
198 | 197 |
#endif |
198 |
+ /* tos*/ |
|
199 |
+ optval=IPTOS_LOWDELAY; |
|
200 |
+ if (setsockopt(s, IPPROTO_IP, IP_TOS, (void*)&optval, sizeof(optval)) ==-1){ |
|
201 |
+ LOG(L_WARN, "WARNING: tcpconn_connect: setsockopt tos: %s\n", |
|
202 |
+ strerror(errno)); |
|
203 |
+ /* continue since this is not critical */ |
|
204 |
+ } |
|
205 |
+ |
|
199 | 206 |
if (connect(s, &server->s, sockaddru_len(*server))<0){ |
200 | 207 |
LOG(L_ERR, "ERROR: tcpconn_connect: connect: (%d) %s\n", |
201 | 208 |
errno, strerror(errno)); |
... | ... |
@@ -491,9 +498,7 @@ void tcpconn_timeout(fd_set* set) |
491 | 498 |
int tcp_init(struct socket_info* sock_info) |
492 | 499 |
{ |
493 | 500 |
union sockaddr_union* addr; |
494 |
-#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR) |
|
495 | 501 |
int optval; |
496 |
-#endif |
|
497 | 502 |
#ifdef DISABLE_NAGLE |
498 | 503 |
int flag; |
499 | 504 |
struct protoent* pe; |
... | ... |
@@ -531,7 +536,7 @@ int tcp_init(struct socket_info* sock_info) |
531 | 536 |
#endif |
532 | 537 |
|
533 | 538 |
|
534 |
-#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR) |
|
539 |
+#if !defined(TCP_DONT_REUSEADDR) |
|
535 | 540 |
/* Stevens, "Network Programming", Section 7.5, "Generic Socket |
536 | 541 |
* Options": "...server started,..a child continues..on existing |
537 | 542 |
* connection..listening server is restarted...call to bind fails |
... | ... |
@@ -549,7 +554,13 @@ int tcp_init(struct socket_info* sock_info) |
549 | 554 |
goto error; |
550 | 555 |
} |
551 | 556 |
#endif |
552 |
- |
|
557 |
+ /* tos */ |
|
558 |
+ optval=IPTOS_LOWDELAY; |
|
559 |
+ if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, |
|
560 |
+ sizeof(optval)) ==-1){ |
|
561 |
+ LOG(L_WARN, "WARNING: tcp_init: setsockopt tos: %s\n", strerror(errno)); |
|
562 |
+ /* continue since this is not critical */ |
|
563 |
+ } |
|
553 | 564 |
if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){ |
554 | 565 |
LOG(L_ERR, "ERROR: tcp_init: bind(%x, %p, %d) on %s: %s\n", |
555 | 566 |
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 | 38 |
#include <sys/types.h> |
38 | 39 |
#include <sys/socket.h> |
39 | 40 |
#include <netinet/in.h> |
41 |
+#include <netinet/ip.h> |
|
40 | 42 |
#include <errno.h> |
41 | 43 |
#include <arpa/inet.h> |
42 | 44 |
#ifdef __linux__ |
... | ... |
@@ -234,6 +236,13 @@ int udp_init(struct socket_info* sock_info) |
234 | 236 |
LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno)); |
235 | 237 |
goto error; |
236 | 238 |
} |
239 |
+ /* tos */ |
|
240 |
+ optval=IPTOS_LOWDELAY; |
|
241 |
+ if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, |
|
242 |
+ sizeof(optval)) ==-1){ |
|
243 |
+ LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n", strerror(errno)); |
|
244 |
+ /* continue since this is not critical */ |
|
245 |
+ } |
|
237 | 246 |
#if defined (__linux__) && defined(UDP_ERRORS) |
238 | 247 |
optval=1; |
239 | 248 |
/* enable error receiving on unconnected sockets */ |