Browse code

tcp internal: send timeout is now kept only in ticks

- removed send_timeout_s and wq_timeout and replaced them with send_timeout,
which is now kept only in ticks. This fixes the cfg.set_delayed_int problem
reported by Miklos.

Andrei Pelinescu-Onciul authored on 20/03/2009 17:26:51
Showing 5 changed files
... ...
@@ -794,7 +794,7 @@ assign_stm:
794 794
 	| TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
795 795
 	| TCP_SEND_TIMEOUT EQUAL NUMBER {
796 796
 		#ifdef USE_TCP
797
-			tcp_default_cfg.send_timeout_s=$3;
797
+			tcp_default_cfg.send_timeout=S_TO_TICKS($3);
798 798
 		#else
799 799
 			warn("tcp support not compiled in");
800 800
 		#endif
... ...
@@ -565,9 +565,9 @@ static void core_tcp_options(rpc_t* rpc, void* c)
565 565
 	if (!tcp_disable){
566 566
 		tcp_options_get(&t);
567 567
 		rpc->add(c, "{", &handle);
568
-		rpc->struct_add(handle, "ddddddddddddddddddddddd",
568
+		rpc->struct_add(handle, "dddddddddddddddddddddd",
569 569
 			"connect_timeout", t.connect_timeout_s,
570
-			"send_timeout",  t.send_timeout_s,
570
+			"send_timeout",  TICKS_TO_S(t.send_timeout),
571 571
 			"connection_lifetime",  TICKS_TO_S(t.con_lifetime),
572 572
 			"max_connections(soft)", t.max_connections,
573 573
 			"no_connect",	t.no_connect,
... ...
@@ -576,7 +576,6 @@ static void core_tcp_options(rpc_t* rpc, void* c)
576 576
 			"connect_wait",	t.tcp_connect_wait,
577 577
 			"conn_wq_max",	t.tcpconn_wq_max,
578 578
 			"wq_max",		t.tcp_wq_max,
579
-			"wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
580 579
 			"defer_accept",	t.defer_accept,
581 580
 			"delayed_ack",	t.delayed_ack,
582 581
 			"syncnt",		t.syncnt,
... ...
@@ -98,6 +98,8 @@
98 98
  *              on write error check if there's still data in the socket 
99 99
  *               read buffer and process it first (andrei)
100 100
  *  2009-02-26  direct blacklist support (andrei)
101
+ *  2009-03-20  s/wq_timeout/send_timeout ; send_timeout is now in ticks
102
+ *              (andrei)
101 103
  */
102 104
 
103 105
 
... ...
@@ -627,7 +629,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, char* data,
627 627
 					" (%d, total %d, last write %d s ago)\n",
628 628
 					size, q->queued, *tcp_total_wq,
629 629
 					TICKS_TO_S(t-q->wr_timeout-
630
-						cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
630
+						cfg_get(tcp, tcp_cfg, send_timeout)));
631 631
 #ifdef USE_DST_BLACKLIST
632 632
 		if (q->first && TICKS_LT(q->wr_timeout, t) &&
633 633
 				cfg_get(core, core_cfg, use_dst_blacklist)){
... ...
@@ -654,7 +656,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, char* data,
654 654
 		q->wr_timeout=get_ticks_raw()+
655 655
 			((c->state==S_CONN_CONNECT)?
656 656
 					S_TO_TICKS(cfg_get(tcp, tcp_cfg, connect_timeout_s)):
657
-					cfg_get(tcp, tcp_cfg, tcp_wq_timeout));
657
+					cfg_get(tcp, tcp_cfg, send_timeout));
658 658
 	}else{
659 659
 		wb=q->last;
660 660
 	}
... ...
@@ -707,7 +709,7 @@ inline static int _wbufq_insert(struct  tcp_connection* c, char* data,
707 707
 					" (%d, total %d, last write %d s ago)\n",
708 708
 					size, q->queued, *tcp_total_wq,
709 709
 					TICKS_TO_S(get_ticks_raw()-q->wr_timeout-
710
-									cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
710
+									cfg_get(tcp, tcp_cfg, send_timeout)));
711 711
 		goto error;
712 712
 	}
713 713
 	if (unlikely(q->offset)){
... ...
@@ -836,7 +838,7 @@ inline static int wbufq_run(int fd, struct tcp_connection* c, int* empty)
836 836
 	}
837 837
 	lock_release(&c->write_lock);
838 838
 	if (likely(ret>0)){
839
-		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, tcp_wq_timeout);
839
+		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, send_timeout);
840 840
 		if (unlikely(c->state==S_CONN_CONNECT || c->state==S_CONN_ACCEPT))
841 841
 			c->state=S_CONN_OK;
842 842
 	}
... ...
@@ -1946,7 +1948,8 @@ send_it:
1946 1946
 #endif
1947 1947
 		/* n=tcp_blocking_write(c, fd, buf, len); */
1948 1948
 		n=tsend_stream(fd, buf, len,
1949
-							cfg_get(tcp, tcp_cfg, send_timeout_s)*1000);
1949
+						TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)) *
1950
+						1000);
1950 1951
 #ifdef TCP_ASYNC
1951 1952
 	}
1952 1953
 #else /* ! TCP_ASYNC */
... ...
@@ -37,31 +37,6 @@
37 37
    NOTE: all the options are initialized in init_tcp_options()
38 38
    depending on compile time defines */
39 39
 struct cfg_group_tcp tcp_default_cfg;
40
-#if 0
41
-{
42
-	1, /* fd_cache, default on */
43
-	/* tcp async options */
44
-	0, /* async / tcp_async, default off */
45
-	1, /* tcp_connect_wait - depends on tcp_async */
46
-	32*1024, /* tcpconn_wq_max - max. write queue len per connection (32k) */
47
-	10*1024*1024, /* tcp_wq_max - max.  overall queued bytes  (10MB)*/
48
-	S_TO_TICKS(tcp_send_timeout), /* tcp_wq_timeout - timeout for queued 
49
-									 writes, depends on tcp_send_timeout */
50
-	/* tcp socket options */
51
-	0, /* defer_accept - on/off*/
52
-	1, /* delayed_ack - delay ack on connect (on/off)*/
53
-	0, /* syncnt - numbers of SYNs retrs. before giving up (0 = OS default) */
54
-	0, /* linger2 - lifetime of orphaned FIN_WAIT2 sockets (0 = OS default)*/
55
-	1, /* keepalive - on/off */
56
-	0, /* keepidle - idle time (s) before tcp starts sending keepalives */
57
-	0, /* keepintvl - interval between keep alives (0 = OS default) */
58
-	0, /* keepcnt - maximum no. of keepalives (0 = OS default)*/
59
-	
60
-	/* other options */
61
-	1 /* crlf_ping - respond to double CRLF ping/keepalive (on/off) */
62
-	
63
-};
64
-#endif
65 40
 
66 41
 
67 42
 
... ...
@@ -80,7 +55,7 @@ static cfg_def_t tcp_cfg_def[] = {
80 80
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),  fix_connect_to,   0,
81 81
 		"used only in non-async mode, in seconds"},
82 82
 	{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC,   -1,
83
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
83
+						MAX_TCP_CON_LIFETIME,               fix_send_to,     0,
84 84
 		"in seconds"},
85 85
 	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
86 86
 						MAX_TCP_CON_LIFETIME,               fix_con_lt,      0,
... ...
@@ -101,7 +76,7 @@ static cfg_def_t tcp_cfg_def[] = {
101 101
 		"maximum bytes queued for write per connection (depends on async)"},
102 102
 	{ "wq_max",       CFG_VAR_INT | CFG_ATOMIC,      0,  1<<30,    0,        0,
103 103
 		"maximum bytes queued for write allowed globally (depends on async)"},
104
-	/* see also wq_timeout below */
104
+	/* see also send_timeout above */
105 105
 	/* tcp socket options */
106 106
 	{ "defer_accept", CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
107 107
 		"0/1 on linux, seconds on freebsd (see docs)"},
... ...
@@ -130,9 +105,6 @@ static cfg_def_t tcp_cfg_def[] = {
130 130
 		"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "},
131 131
 	/* internal and/or "fixed" versions of some vars
132 132
 	   (not supposed to be writeable, read will provide only debugging value*/
133
-	{ "wq_timeout_ticks",   CFG_VAR_INT | CFG_READONLY, 0,
134
-									MAX_TCP_CON_LIFETIME,         0,         0,
135
-		"internal send_timeout value in ticks, used in async. mode"},
136 133
 	{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC,    512,    65536,  0,         0,
137 134
 		"internal read buffer size (should be > max. expected datagram)"},
138 135
 	{ "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC,    1,    65535,  0,         0,
... ...
@@ -147,14 +119,13 @@ void* tcp_cfg; /* tcp config handle */
147 147
 void init_tcp_options()
148 148
 {
149 149
 	tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT;
150
-	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
150
+	tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT);
151 151
 	tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S);
152 152
 	tcp_default_cfg.max_connections=tcp_max_connections;
153 153
 #ifdef TCP_ASYNC
154 154
 	tcp_default_cfg.async=1;
155 155
 	tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */
156 156
 	tcp_default_cfg.tcp_wq_max=10*1024*1024; /* 10 MB */
157
-	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
158 157
 #ifdef TCP_CONNECT_WAIT
159 158
 	tcp_default_cfg.tcp_connect_wait=1;
160 159
 #endif /* TCP_CONNECT_WAIT */
... ...
@@ -230,13 +201,10 @@ static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val)
230 230
 static int fix_send_to(void* cfg_h, str* gname, str* name, void** val)
231 231
 {
232 232
 	int v;
233
-	v=(int)(long)*val;
234
-	fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
235
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
233
+	v=S_TO_TICKS((int)(long)*val);
234
+	fix_timeout("tcp_send_timeout", &v, S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
235
+						MAX_TCP_CON_LIFETIME);
236 236
 	*val=(void*)(long)v;
237
-#ifdef TCP_ASYNC
238
-	((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
239
-#endif /* TCP_ASYNC */
240 237
 	return 0;
241 238
 }
242 239
 
... ...
@@ -311,7 +279,6 @@ void tcp_options_check()
311 311
 	W_OPT_NC(async);
312 312
 	W_OPT_NC(tcpconn_wq_max);
313 313
 	W_OPT_NC(tcp_wq_max);
314
-	W_OPT_NC(tcp_wq_timeout);
315 314
 #endif /* TCP_ASYNC */
316 315
 #ifndef TCP_CONNECT_WAIT
317 316
 	W_OPT_NC(tcp_connect_wait);
... ...
@@ -353,19 +320,14 @@ void tcp_options_check()
353 353
 	fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s,
354 354
 						DEFAULT_TCP_CONNECT_TIMEOUT,
355 355
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
356
-	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout_s,
357
-						DEFAULT_TCP_SEND_TIMEOUT,
358
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
356
+	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout,
357
+						S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
358
+						MAX_TCP_CON_LIFETIME);
359 359
 	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
360 360
 						MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
361
-	/* compute timeout in ticks */
362
-#ifdef TCP_ASYNC
363
-	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
364
-#endif /* TCP_ASYNC */
365 361
 	tcp_default_cfg.max_connections=tcp_max_connections;
366 362
 	tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size);
367 363
 	tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size);
368
-	
369 364
 }
370 365
 
371 366
 
... ...
@@ -112,8 +112,8 @@
112 112
 struct cfg_group_tcp{
113 113
 	/* ser tcp options, low level */
114 114
 	int connect_timeout_s; /* in s */
115
-	int send_timeout_s; /* in s */
116
-	int con_lifetime; /* s fixed to ticks */
115
+	int send_timeout; /* in ticks (s fixed to ticks) */
116
+	int con_lifetime; /* in ticks (s fixed to ticks) */
117 117
 	int max_connections;
118 118
 	int no_connect; /* do not open any new tcp connection (but accept them) */
119 119
 	int fd_cache; /* on /off */
... ...
@@ -139,7 +139,6 @@ struct cfg_group_tcp{
139 139
 	int alias_flags;
140 140
 	int new_conn_alias_flags;
141 141
 	/* internal, "fixed" vars */
142
-	unsigned int tcp_wq_timeout; /* in ticks, timeout for queued writes */
143 142
 	unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
144 143
 	unsigned int wq_blk_size; /* async write block size (debugging use) */
145 144
 };