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 153
 # -DUSE_TCP
153 154
 #		compiles in tcp support (highly experimental for now, it will probably
154 155
 #		not work, use it only if you really now what you are doing)
156
+# -DDISABLE_NAGLE
157
+#		disable the tcp Nagle algorithm (lower delay)
155 158
 # -DVOICE_MAIL
156 159
 #               enables voicemail support in ser core and in tm module
157 160
 #               voicemail needs also -D_TOTAG
... ...
@@ -167,6 +170,8 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
167 170
 	 -DVOICE_MAIL \
168 171
 	 -D_TOTAG \
169 172
 	 -DUSE_TCP \
173
+	 -DDISABLE_NAGLE \
174
+	 -DDBG_QM_MALLOC \
170 175
 	 #-DF_MALLOC \
171 176
 	 #-DNO_DEBUG \
172 177
 	 #-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 47
 #include <sys/types.h>
39 48
 #include <sys/select.h>
40 49
 #include <sys/socket.h>
50
+#include <netinet/tcp.h>
41 51
 #include <sys/uio.h>  /* writev*/
52
+#include <netdb.h>
42 53
 
43 54
 #include <unistd.h>
44 55
 
... ...
@@ -88,6 +99,7 @@ static int connection_id=1; /*  unique for each connection, used for
88 99
 								for a reply */
89 100
 int unix_tcp_sock;
90 101
 
102
+int tcp_proto_no=-1; /* tcp protocol number as returned by getprotobyname */
91 103
 
92 104
 
93 105
 struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
... ...
@@ -136,6 +148,9 @@ error:
136 148
 struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
137 149
 {
138 150
 	int s;
151
+#ifdef DISABLE_NAGLE
152
+	int flag;
153
+#endif
139 154
 
140 155
 	s=socket(AF2PF(server->s.sa_family), SOCK_STREAM, 0);
141 156
 	if (s<0){
... ...
@@ -143,6 +158,15 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
143 158
 				errno, strerror(errno));
144 159
 		goto error;
145 160
 	}
161
+#ifdef DISABLE_NAGLE
162
+	flag=1;
163
+	if ( (tcp_proto_no!=-1) && 
164
+		  (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY,
165
+					&flag, sizeof(flag))<0) ){
166
+		LOG(L_ERR, "ERROR: tcp_connect: could not disable Nagle: %s\n",
167
+				strerror(errno));
168
+	}
169
+#endif
146 170
 	if (connect(s, &server->s, sockaddru_len(*server))<0){
147 171
 		LOG(L_ERR, "ERROR: tcpconn_connect: connect: (%d) %s\n",
148 172
 				errno, strerror(errno));
... ...
@@ -417,6 +441,18 @@ void tcpconn_timeout(fd_set* set)
417 441
 int tcp_init(struct socket_info* sock_info)
418 442
 {
419 443
 	union sockaddr_union* addr;
444
+#ifdef DISABLE_NAGLE
445
+	int flag;
446
+	struct protoent* pe;
447
+	
448
+	pe=getprotobyname("tcp");
449
+	if (pe==0){
450
+		LOG(L_ERR, "ERROR: tcp_init: could not get TCP protocol number\n");
451
+		tcp_proto_no=-1;
452
+	}else{
453
+		tcp_proto_no=pe->p_proto;
454
+	}
455
+#endif
420 456
 	
421 457
 	addr=&sock_info->su;
422 458
 	sock_info->proto=PROTO_TCP;
... ...
@@ -429,6 +465,15 @@ int tcp_init(struct socket_info* sock_info)
429 465
 		LOG(L_ERR, "ERROR: tcp_init: socket: %s\n", strerror(errno));
430 466
 		goto error;
431 467
 	}
468
+#ifdef DISABLE_NAGLE
469
+	flag=1;
470
+	if ( (tcp_proto_no!=-1) &&
471
+		 (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY,
472
+					 &flag, sizeof(flag))<0) ){
473
+		LOG(L_ERR, "ERROR: tcp_init: could not disable Nagle: %s\n",
474
+				strerror(errno));
475
+	}
476
+#endif
432 477
 	if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){
433 478
 		LOG(L_ERR, "ERROR: tcp_init: bind(%x, %p, %d) on %s: %s\n",
434 479
 				sock_info->socket, &addr->s,