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 629
 					" (%d, total %d, last write %d s ago)\n",
628 630
 					size, q->queued, *tcp_total_wq,
629 631
 					TICKS_TO_S(t-q->wr_timeout-
630
-						cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
632
+						cfg_get(tcp, tcp_cfg, send_timeout)));
631 633
 #ifdef USE_DST_BLACKLIST
632 634
 		if (q->first && TICKS_LT(q->wr_timeout, t) &&
633 635
 				cfg_get(core, core_cfg, use_dst_blacklist)){
... ...
@@ -654,7 +656,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, char* data,
654 656
 		q->wr_timeout=get_ticks_raw()+
655 657
 			((c->state==S_CONN_CONNECT)?
656 658
 					S_TO_TICKS(cfg_get(tcp, tcp_cfg, connect_timeout_s)):
657
-					cfg_get(tcp, tcp_cfg, tcp_wq_timeout));
659
+					cfg_get(tcp, tcp_cfg, send_timeout));
658 660
 	}else{
659 661
 		wb=q->last;
660 662
 	}
... ...
@@ -707,7 +709,7 @@ inline static int _wbufq_insert(struct  tcp_connection* c, char* data,
707 709
 					" (%d, total %d, last write %d s ago)\n",
708 710
 					size, q->queued, *tcp_total_wq,
709 711
 					TICKS_TO_S(get_ticks_raw()-q->wr_timeout-
710
-									cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
712
+									cfg_get(tcp, tcp_cfg, send_timeout)));
711 713
 		goto error;
712 714
 	}
713 715
 	if (unlikely(q->offset)){
... ...
@@ -836,7 +838,7 @@ inline static int wbufq_run(int fd, struct tcp_connection* c, int* empty)
836 838
 	}
837 839
 	lock_release(&c->write_lock);
838 840
 	if (likely(ret>0)){
839
-		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, tcp_wq_timeout);
841
+		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, send_timeout);
840 842
 		if (unlikely(c->state==S_CONN_CONNECT || c->state==S_CONN_ACCEPT))
841 843
 			c->state=S_CONN_OK;
842 844
 	}
... ...
@@ -1946,7 +1948,8 @@ send_it:
1946 1948
 #endif
1947 1949
 		/* n=tcp_blocking_write(c, fd, buf, len); */
1948 1950
 		n=tsend_stream(fd, buf, len,
1949
-							cfg_get(tcp, tcp_cfg, send_timeout_s)*1000);
1951
+						TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)) *
1952
+						1000);
1950 1953
 #ifdef TCP_ASYNC
1951 1954
 	}
1952 1955
 #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 55
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),  fix_connect_to,   0,
81 56
 		"used only in non-async mode, in seconds"},
82 57
 	{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC,   -1,
83
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
58
+						MAX_TCP_CON_LIFETIME,               fix_send_to,     0,
84 59
 		"in seconds"},
85 60
 	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
86 61
 						MAX_TCP_CON_LIFETIME,               fix_con_lt,      0,
... ...
@@ -101,7 +76,7 @@ static cfg_def_t tcp_cfg_def[] = {
101 76
 		"maximum bytes queued for write per connection (depends on async)"},
102 77
 	{ "wq_max",       CFG_VAR_INT | CFG_ATOMIC,      0,  1<<30,    0,        0,
103 78
 		"maximum bytes queued for write allowed globally (depends on async)"},
104
-	/* see also wq_timeout below */
79
+	/* see also send_timeout above */
105 80
 	/* tcp socket options */
106 81
 	{ "defer_accept", CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
107 82
 		"0/1 on linux, seconds on freebsd (see docs)"},
... ...
@@ -130,9 +105,6 @@ static cfg_def_t tcp_cfg_def[] = {
130 105
 		"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "},
131 106
 	/* internal and/or "fixed" versions of some vars
132 107
 	   (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 108
 	{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC,    512,    65536,  0,         0,
137 109
 		"internal read buffer size (should be > max. expected datagram)"},
138 110
 	{ "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC,    1,    65535,  0,         0,
... ...
@@ -147,14 +119,13 @@ void* tcp_cfg; /* tcp config handle */
147 119
 void init_tcp_options()
148 120
 {
149 121
 	tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT;
150
-	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
122
+	tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT);
151 123
 	tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S);
152 124
 	tcp_default_cfg.max_connections=tcp_max_connections;
153 125
 #ifdef TCP_ASYNC
154 126
 	tcp_default_cfg.async=1;
155 127
 	tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */
156 128
 	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 129
 #ifdef TCP_CONNECT_WAIT
159 130
 	tcp_default_cfg.tcp_connect_wait=1;
160 131
 #endif /* TCP_CONNECT_WAIT */
... ...
@@ -230,13 +201,10 @@ static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val)
230 201
 static int fix_send_to(void* cfg_h, str* gname, str* name, void** val)
231 202
 {
232 203
 	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));
204
+	v=S_TO_TICKS((int)(long)*val);
205
+	fix_timeout("tcp_send_timeout", &v, S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
206
+						MAX_TCP_CON_LIFETIME);
236 207
 	*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 208
 	return 0;
241 209
 }
242 210
 
... ...
@@ -311,7 +279,6 @@ void tcp_options_check()
311 279
 	W_OPT_NC(async);
312 280
 	W_OPT_NC(tcpconn_wq_max);
313 281
 	W_OPT_NC(tcp_wq_max);
314
-	W_OPT_NC(tcp_wq_timeout);
315 282
 #endif /* TCP_ASYNC */
316 283
 #ifndef TCP_CONNECT_WAIT
317 284
 	W_OPT_NC(tcp_connect_wait);
... ...
@@ -353,19 +320,14 @@ void tcp_options_check()
353 320
 	fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s,
354 321
 						DEFAULT_TCP_CONNECT_TIMEOUT,
355 322
 						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));
323
+	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout,
324
+						S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
325
+						MAX_TCP_CON_LIFETIME);
359 326
 	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
360 327
 						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 328
 	tcp_default_cfg.max_connections=tcp_max_connections;
366 329
 	tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size);
367 330
 	tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size);
368
-	
369 331
 }
370 332
 
371 333
 
... ...
@@ -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
 };