Ver Fonte

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 há 16 anos atrás
pai
commit
ffc72fcf04
5 ficheiros alterados com 22 adições e 59 exclusões
  1. 1 1
      cfg.y
  2. 2 3
      core_cmd.c
  3. 8 5
      tcp_main.c
  4. 9 47
      tcp_options.c
  5. 2 3
      tcp_options.h

+ 1 - 1
cfg.y

@@ -794,7 +794,7 @@ assign_stm:
 	| TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
 	| TCP_SEND_TIMEOUT EQUAL NUMBER {
 		#ifdef USE_TCP
-			tcp_default_cfg.send_timeout_s=$3;
+			tcp_default_cfg.send_timeout=S_TO_TICKS($3);
 		#else
 			warn("tcp support not compiled in");
 		#endif

+ 2 - 3
core_cmd.c

@@ -565,9 +565,9 @@ static void core_tcp_options(rpc_t* rpc, void* c)
 	if (!tcp_disable){
 		tcp_options_get(&t);
 		rpc->add(c, "{", &handle);
-		rpc->struct_add(handle, "ddddddddddddddddddddddd",
+		rpc->struct_add(handle, "dddddddddddddddddddddd",
 			"connect_timeout", t.connect_timeout_s,
-			"send_timeout",  t.send_timeout_s,
+			"send_timeout",  TICKS_TO_S(t.send_timeout),
 			"connection_lifetime",  TICKS_TO_S(t.con_lifetime),
 			"max_connections(soft)", t.max_connections,
 			"no_connect",	t.no_connect,
@@ -576,7 +576,6 @@ static void core_tcp_options(rpc_t* rpc, void* c)
 			"connect_wait",	t.tcp_connect_wait,
 			"conn_wq_max",	t.tcpconn_wq_max,
 			"wq_max",		t.tcp_wq_max,
-			"wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
 			"defer_accept",	t.defer_accept,
 			"delayed_ack",	t.delayed_ack,
 			"syncnt",		t.syncnt,

+ 8 - 5
tcp_main.c

@@ -98,6 +98,8 @@
  *              on write error check if there's still data in the socket 
  *               read buffer and process it first (andrei)
  *  2009-02-26  direct blacklist support (andrei)
+ *  2009-03-20  s/wq_timeout/send_timeout ; send_timeout is now in ticks
+ *              (andrei)
  */
 
 
@@ -627,7 +629,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, char* data,
 					" (%d, total %d, last write %d s ago)\n",
 					size, q->queued, *tcp_total_wq,
 					TICKS_TO_S(t-q->wr_timeout-
-						cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
+						cfg_get(tcp, tcp_cfg, send_timeout)));
 #ifdef USE_DST_BLACKLIST
 		if (q->first && TICKS_LT(q->wr_timeout, t) &&
 				cfg_get(core, core_cfg, use_dst_blacklist)){
@@ -654,7 +656,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, char* data,
 		q->wr_timeout=get_ticks_raw()+
 			((c->state==S_CONN_CONNECT)?
 					S_TO_TICKS(cfg_get(tcp, tcp_cfg, connect_timeout_s)):
-					cfg_get(tcp, tcp_cfg, tcp_wq_timeout));
+					cfg_get(tcp, tcp_cfg, send_timeout));
 	}else{
 		wb=q->last;
 	}
@@ -707,7 +709,7 @@ inline static int _wbufq_insert(struct  tcp_connection* c, char* data,
 					" (%d, total %d, last write %d s ago)\n",
 					size, q->queued, *tcp_total_wq,
 					TICKS_TO_S(get_ticks_raw()-q->wr_timeout-
-									cfg_get(tcp, tcp_cfg, tcp_wq_timeout)));
+									cfg_get(tcp, tcp_cfg, send_timeout)));
 		goto error;
 	}
 	if (unlikely(q->offset)){
@@ -836,7 +838,7 @@ inline static int wbufq_run(int fd, struct tcp_connection* c, int* empty)
 	}
 	lock_release(&c->write_lock);
 	if (likely(ret>0)){
-		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, tcp_wq_timeout);
+		q->wr_timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, send_timeout);
 		if (unlikely(c->state==S_CONN_CONNECT || c->state==S_CONN_ACCEPT))
 			c->state=S_CONN_OK;
 	}
@@ -1946,7 +1948,8 @@ send_it:
 #endif
 		/* n=tcp_blocking_write(c, fd, buf, len); */
 		n=tsend_stream(fd, buf, len,
-							cfg_get(tcp, tcp_cfg, send_timeout_s)*1000);
+						TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)) *
+						1000);
 #ifdef TCP_ASYNC
 	}
 #else /* ! TCP_ASYNC */

+ 9 - 47
tcp_options.c

@@ -37,31 +37,6 @@
    NOTE: all the options are initialized in init_tcp_options()
    depending on compile time defines */
 struct cfg_group_tcp tcp_default_cfg;
-#if 0
-{
-	1, /* fd_cache, default on */
-	/* tcp async options */
-	0, /* async / tcp_async, default off */
-	1, /* tcp_connect_wait - depends on tcp_async */
-	32*1024, /* tcpconn_wq_max - max. write queue len per connection (32k) */
-	10*1024*1024, /* tcp_wq_max - max.  overall queued bytes  (10MB)*/
-	S_TO_TICKS(tcp_send_timeout), /* tcp_wq_timeout - timeout for queued 
-									 writes, depends on tcp_send_timeout */
-	/* tcp socket options */
-	0, /* defer_accept - on/off*/
-	1, /* delayed_ack - delay ack on connect (on/off)*/
-	0, /* syncnt - numbers of SYNs retrs. before giving up (0 = OS default) */
-	0, /* linger2 - lifetime of orphaned FIN_WAIT2 sockets (0 = OS default)*/
-	1, /* keepalive - on/off */
-	0, /* keepidle - idle time (s) before tcp starts sending keepalives */
-	0, /* keepintvl - interval between keep alives (0 = OS default) */
-	0, /* keepcnt - maximum no. of keepalives (0 = OS default)*/
-	
-	/* other options */
-	1 /* crlf_ping - respond to double CRLF ping/keepalive (on/off) */
-	
-};
-#endif
 
 
 
@@ -80,7 +55,7 @@ static cfg_def_t tcp_cfg_def[] = {
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),  fix_connect_to,   0,
 		"used only in non-async mode, in seconds"},
 	{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC,   -1,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
+						MAX_TCP_CON_LIFETIME,               fix_send_to,     0,
 		"in seconds"},
 	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
 						MAX_TCP_CON_LIFETIME,               fix_con_lt,      0,
@@ -101,7 +76,7 @@ static cfg_def_t tcp_cfg_def[] = {
 		"maximum bytes queued for write per connection (depends on async)"},
 	{ "wq_max",       CFG_VAR_INT | CFG_ATOMIC,      0,  1<<30,    0,        0,
 		"maximum bytes queued for write allowed globally (depends on async)"},
-	/* see also wq_timeout below */
+	/* see also send_timeout above */
 	/* tcp socket options */
 	{ "defer_accept", CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
 		"0/1 on linux, seconds on freebsd (see docs)"},
@@ -130,9 +105,6 @@ static cfg_def_t tcp_cfg_def[] = {
 		"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "},
 	/* internal and/or "fixed" versions of some vars
 	   (not supposed to be writeable, read will provide only debugging value*/
-	{ "wq_timeout_ticks",   CFG_VAR_INT | CFG_READONLY, 0,
-									MAX_TCP_CON_LIFETIME,         0,         0,
-		"internal send_timeout value in ticks, used in async. mode"},
 	{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC,    512,    65536,  0,         0,
 		"internal read buffer size (should be > max. expected datagram)"},
 	{ "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC,    1,    65535,  0,         0,
@@ -147,14 +119,13 @@ void* tcp_cfg; /* tcp config handle */
 void init_tcp_options()
 {
 	tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT;
-	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
+	tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT);
 	tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S);
 	tcp_default_cfg.max_connections=tcp_max_connections;
 #ifdef TCP_ASYNC
 	tcp_default_cfg.async=1;
 	tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */
 	tcp_default_cfg.tcp_wq_max=10*1024*1024; /* 10 MB */
-	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
 #ifdef TCP_CONNECT_WAIT
 	tcp_default_cfg.tcp_connect_wait=1;
 #endif /* TCP_CONNECT_WAIT */
@@ -230,13 +201,10 @@ static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val)
 static int fix_send_to(void* cfg_h, str* gname, str* name, void** val)
 {
 	int v;
-	v=(int)(long)*val;
-	fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	v=S_TO_TICKS((int)(long)*val);
+	fix_timeout("tcp_send_timeout", &v, S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
+						MAX_TCP_CON_LIFETIME);
 	*val=(void*)(long)v;
-#ifdef TCP_ASYNC
-	((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
-#endif /* TCP_ASYNC */
 	return 0;
 }
 
@@ -311,7 +279,6 @@ void tcp_options_check()
 	W_OPT_NC(async);
 	W_OPT_NC(tcpconn_wq_max);
 	W_OPT_NC(tcp_wq_max);
-	W_OPT_NC(tcp_wq_timeout);
 #endif /* TCP_ASYNC */
 #ifndef TCP_CONNECT_WAIT
 	W_OPT_NC(tcp_connect_wait);
@@ -353,19 +320,14 @@ void tcp_options_check()
 	fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s,
 						DEFAULT_TCP_CONNECT_TIMEOUT,
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
-	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout_s,
-						DEFAULT_TCP_SEND_TIMEOUT,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout,
+						S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT),
+						MAX_TCP_CON_LIFETIME);
 	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
 						MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
-	/* compute timeout in ticks */
-#ifdef TCP_ASYNC
-	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
-#endif /* TCP_ASYNC */
 	tcp_default_cfg.max_connections=tcp_max_connections;
 	tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size);
 	tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size);
-	
 }
 
 

+ 2 - 3
tcp_options.h

@@ -112,8 +112,8 @@
 struct cfg_group_tcp{
 	/* ser tcp options, low level */
 	int connect_timeout_s; /* in s */
-	int send_timeout_s; /* in s */
-	int con_lifetime; /* s fixed to ticks */
+	int send_timeout; /* in ticks (s fixed to ticks) */
+	int con_lifetime; /* in ticks (s fixed to ticks) */
 	int max_connections;
 	int no_connect; /* do not open any new tcp connection (but accept them) */
 	int fd_cache; /* on /off */
@@ -139,7 +139,6 @@ struct cfg_group_tcp{
 	int alias_flags;
 	int new_conn_alias_flags;
 	/* internal, "fixed" vars */
-	unsigned int tcp_wq_timeout; /* in ticks, timeout for queued writes */
 	unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
 	unsigned int wq_blk_size; /* async write block size (debugging use) */
 };