Browse code

- if DISABLE_NAGLE is defined (by default it is) the Nagle algoritm will be turend off => lower tcp delays

Andrei Pelinescu-Onciul authored on 25/02/2003 16:58:57
Showing 3 changed files
... ...
@@ -6,14 +6,15 @@
6 6
 # --------
7 7
 #              created by andrei
8 8
 #  2003-02-24  added LOCALBASE, fixed doc-dir for freebsd - patch provided
9
-#              by Maxim Sobolev <sobomax@FreeBSD.org>
9
+#               by Maxim Sobolev <sobomax@FreeBSD.org>
10
+#  2003-02-25  added -DDISABLE_NAGLE
10 11
 
11 12
 
12 13
 #version number
13 14
 VERSION = 0
14 15
 PATCHLEVEL = 8
15 16
 SUBLEVEL =   11
16
-EXTRAVERSION = pre6-tcp8-tm
17
+EXTRAVERSION = pre6-tcp9-tm
17 18
 
18 19
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
19 20
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -152,6 +153,8 @@ YACC := $(shell echo "$${YACC}")
152 152
 # -DUSE_TCP
153 153
 #		compiles in tcp support (highly experimental for now, it will probably
154 154
 #		not work, use it only if you really now what you are doing)
155
+# -DDISABLE_NAGLE
156
+#		disable the tcp Nagle algorithm (lower delay)
155 157
 # -DVOICE_MAIL
156 158
 #               enables voicemail support in ser core and in tm module
157 159
 #               voicemail needs also -D_TOTAG
... ...
@@ -167,6 +170,8 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
167 167
 	 -DVOICE_MAIL \
168 168
 	 -D_TOTAG \
169 169
 	 -DUSE_TCP \
170
+	 -DDISABLE_NAGLE \
171
+	 -DDBG_QM_MALLOC \
170 172
 	 #-DF_MALLOC \
171 173
 	 #-DNO_DEBUG \
172 174
 	 #-DNO_LOG
... ...
@@ -106,6 +106,9 @@ static char flags[]=
106 106
 #ifdef USE_TCP
107 107
 ", USE_TCP"
108 108
 #endif
109
+#ifdef DISABLE_NAGLE
110
+", DISABLE_NAGLE"
111
+#endif
109 112
 #ifdef NO_DEBUG
110 113
 ", NO_DEBUG"
111 114
 #endif
... ...
@@ -24,6 +24,15 @@
24 24
  * along with this program; if not, write to the Free Software
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+/*
28
+ * History:
29
+ * --------
30
+ *  2002-11-29  created by andrei
31
+ *  2002-12-11  added tcp_send (andrei)
32
+ *  2003-01-20  locking fixes, hashtables (andrei)
33
+ *  2003-02-20  s/lock_t/gen_lock_t/ to avoid a conflict on solaris (andrei)
34
+ *  2003-02-25  Nagle is disabled if -DDISABLE_NAGLE (andrei)
35
+ */
27 36
 
28 37
 
29 38
 #ifdef USE_TCP
... ...
@@ -38,7 +47,9 @@
38 38
 #include <sys/types.h>
39 39
 #include <sys/select.h>
40 40
 #include <sys/socket.h>
41
+#include <netinet/tcp.h>
41 42
 #include <sys/uio.h>  /* writev*/
43
+#include <netdb.h>
42 44
 
43 45
 #include <unistd.h>
44 46
 
... ...
@@ -88,6 +99,7 @@ static int connection_id=1; /*  unique for each connection, used for
88 88
 								for a reply */
89 89
 int unix_tcp_sock;
90 90
 
91
+int tcp_proto_no=-1; /* tcp protocol number as returned by getprotobyname */
91 92
 
92 93
 
93 94
 struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
... ...
@@ -136,6 +148,9 @@ error:
136 136
 struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
137 137
 {
138 138
 	int s;
139
+#ifdef DISABLE_NAGLE
140
+	int flag;
141
+#endif
139 142
 
140 143
 	s=socket(AF2PF(server->s.sa_family), SOCK_STREAM, 0);
141 144
 	if (s<0){
... ...
@@ -143,6 +158,15 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
143 143
 				errno, strerror(errno));
144 144
 		goto error;
145 145
 	}
146
+#ifdef DISABLE_NAGLE
147
+	flag=1;
148
+	if ( (tcp_proto_no!=-1) && 
149
+		  (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY,
150
+					&flag, sizeof(flag))<0) ){
151
+		LOG(L_ERR, "ERROR: tcp_connect: could not disable Nagle: %s\n",
152
+				strerror(errno));
153
+	}
154
+#endif
146 155
 	if (connect(s, &server->s, sockaddru_len(*server))<0){
147 156
 		LOG(L_ERR, "ERROR: tcpconn_connect: connect: (%d) %s\n",
148 157
 				errno, strerror(errno));
... ...
@@ -417,6 +441,18 @@ void tcpconn_timeout(fd_set* set)
417 417
 int tcp_init(struct socket_info* sock_info)
418 418
 {
419 419
 	union sockaddr_union* addr;
420
+#ifdef DISABLE_NAGLE
421
+	int flag;
422
+	struct protoent* pe;
423
+	
424
+	pe=getprotobyname("tcp");
425
+	if (pe==0){
426
+		LOG(L_ERR, "ERROR: tcp_init: could not get TCP protocol number\n");
427
+		tcp_proto_no=-1;
428
+	}else{
429
+		tcp_proto_no=pe->p_proto;
430
+	}
431
+#endif
420 432
 	
421 433
 	addr=&sock_info->su;
422 434
 	sock_info->proto=PROTO_TCP;
... ...
@@ -429,6 +465,15 @@ int tcp_init(struct socket_info* sock_info)
429 429
 		LOG(L_ERR, "ERROR: tcp_init: socket: %s\n", strerror(errno));
430 430
 		goto error;
431 431
 	}
432
+#ifdef DISABLE_NAGLE
433
+	flag=1;
434
+	if ( (tcp_proto_no!=-1) &&
435
+		 (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY,
436
+					 &flag, sizeof(flag))<0) ){
437
+		LOG(L_ERR, "ERROR: tcp_init: could not disable Nagle: %s\n",
438
+				strerror(errno));
439
+	}
440
+#endif
432 441
 	if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){
433 442
 		LOG(L_ERR, "ERROR: tcp_init: bind(%x, %p, %d) on %s: %s\n",
434 443
 				sock_info->socket, &addr->s,