Browse code

tcp: async mode on by default

- async mode is now on by default (use tcp_async=no in the config
to disable it)
- renamed tcp_buf_write/TCP_BUF_WRITE into tcp_async/TCP_ASYNC in
the code

Andrei Pelinescu-Onciul authored on 05/03/2009 17:21:11
Showing 7 changed files
... ...
@@ -273,10 +273,10 @@ new config variables:
273 273
      will be cached inside the process calling tcp_send (performance increase
274 274
      for sending over tcp at the cost of slightly slower connection closing and
275 275
      extra FDs kept open)
276
-  tcp_async = yes | no (default no) - if enabled all the tcp  writes that 
276
+  tcp_async = yes | no (default yes) - if enabled all the tcp  writes that 
277 277
      would block / wait for connect to finish, will be queued and attempted
278 278
      latter (see also tcp_conn_wq_max and tcp_wq_max).
279
-  tcp_buf_write = synonim for tcp_async
279
+  tcp_buf_write = obsoleted synonim for tcp_async
280 280
   tcp_conn_wq_max = bytes (default 32 K) - maximum bytes queued for write 
281 281
      allowed per connection. Attempting to queue more bytes would result
282 282
      in an error and in the connection being closed (too slow). If 
... ...
@@ -873,7 +873,7 @@ assign_stm:
873 873
 	| TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
874 874
 	| TCP_OPT_BUF_WRITE EQUAL NUMBER {
875 875
 		#ifdef USE_TCP
876
-			tcp_default_cfg.tcp_buf_write=$3;
876
+			tcp_default_cfg.async=$3;
877 877
 		#else
878 878
 			warn("tcp support not compiled in");
879 879
 		#endif
... ...
@@ -571,7 +571,7 @@ static void core_tcp_options(rpc_t* rpc, void* c)
571 571
 			"connection_lifetime",  t.con_lifetime_s,
572 572
 			"max_connections(soft)", t.max_connections,
573 573
 			"fd_cache",		t.fd_cache,
574
-			"async",		t.tcp_buf_write,
574
+			"async",		t.async,
575 575
 			"connect_wait",	t.tcp_connect_wait,
576 576
 			"conn_wq_max",	t.tcpconn_wq_max,
577 577
 			"wq_max",		t.tcp_wq_max,
... ...
@@ -132,7 +132,7 @@ struct tcp_conn_alias{
132 132
 };
133 133
 
134 134
 
135
-#ifdef TCP_BUF_WRITE
135
+#ifdef TCP_ASYNC
136 136
 	struct tcp_wbuffer{
137 137
 		struct tcp_wbuffer* next;
138 138
 		unsigned int b_size;
... ...
@@ -174,7 +174,7 @@ struct tcp_connection{
174 174
 	struct tcp_connection* c_prev;
175 175
 	struct tcp_conn_alias con_aliases[TCP_CON_MAX_ALIASES];
176 176
 	int aliases; /* aliases number, at least 1 */
177
-#ifdef TCP_BUF_WRITE
177
+#ifdef TCP_ASYNC
178 178
 	struct tcp_wbuffer_queue wbuf_q;
179 179
 #endif
180 180
 };
... ...
@@ -207,7 +207,7 @@
207 207
 #define TCPCONN_TIMEOUT_MIN_RUN 1  /* once per tick */
208 208
 #define TCPCONN_WAIT_TIMEOUT 1 /* 1 tick */
209 209
 
210
-#ifdef TCP_BUF_WRITE
210
+#ifdef TCP_ASYNC
211 211
 #define TCP_WBUF_SIZE	1024 /* FIXME: after debugging switch to 16-32k */
212 212
 static unsigned int* tcp_total_wq=0;
213 213
 #endif
... ...
@@ -598,7 +598,7 @@ inline static int _tcpconn_write_nb(int fd, struct tcp_connection* c,
598 598
 									char* buf, int len);
599 599
 
600 600
 
601
-#ifdef TCP_BUF_WRITE
601
+#ifdef TCP_ASYNC
602 602
 
603 603
 
604 604
 /* unsafe version */
... ...
@@ -841,7 +841,7 @@ inline static int wbufq_run(int fd, struct tcp_connection* c, int* empty)
841 841
 	return ret;
842 842
 }
843 843
 
844
-#endif /* TCP_BUF_WRITE */
844
+#endif /* TCP_ASYNC */
845 845
 
846 846
 
847 847
 
... ...
@@ -995,9 +995,9 @@ inline static int tcp_do_connect(	union sockaddr_union* server,
995 995
 	union sockaddr_union my_name;
996 996
 	socklen_t my_name_len;
997 997
 	struct ip_addr ip;
998
-#ifdef TCP_BUF_WRITE
998
+#ifdef TCP_ASYNC
999 999
 	int n;
1000
-#endif /* TCP_BUF_WRITE */
1000
+#endif /* TCP_ASYNC */
1001 1001
 
1002 1002
 	s=socket(AF2PF(server->s.sa_family), SOCK_STREAM, 0);
1003 1003
 	if (unlikely(s==-1)){
... ...
@@ -1017,8 +1017,8 @@ inline static int tcp_do_connect(	union sockaddr_union* server,
1017 1017
 					strerror(errno), errno);
1018 1018
 	}
1019 1019
 	*state=S_CONN_OK;
1020
-#ifdef TCP_BUF_WRITE
1021
-	if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
1020
+#ifdef TCP_ASYNC
1021
+	if (likely(cfg_get(tcp, tcp_cfg, async))){
1022 1022
 again:
1023 1023
 		n=connect(s, &server->s, sockaddru_len(*server));
1024 1024
 		if (unlikely(n==-1)){
... ...
@@ -1046,16 +1046,16 @@ again:
1046 1046
 			}
1047 1047
 		}
1048 1048
 	}else{
1049
-#endif /* TCP_BUF_WRITE */
1049
+#endif /* TCP_ASYNC */
1050 1050
 		if (tcp_blocking_connect(s, type, &server->s,
1051 1051
 									sockaddru_len(*server))<0){
1052 1052
 			LOG(L_ERR, "ERROR: tcp_do_connect: tcp_blocking_connect %s"
1053 1053
 						" failed\n", su2a(server, sizeof(*server)));
1054 1054
 			goto error;
1055 1055
 		}
1056
-#ifdef TCP_BUF_WRITE
1056
+#ifdef TCP_ASYNC
1057 1057
 	}
1058
-#endif /* TCP_BUF_WRITE */
1058
+#endif /* TCP_ASYNC */
1059 1059
 	if (from){
1060 1060
 		su2ip_addr(&ip, from);
1061 1061
 		if (!ip_addr_any(&ip))
... ...
@@ -1256,7 +1256,7 @@ static inline void _tcpconn_detach(struct tcp_connection *c)
1256 1256
 
1257 1257
 static inline void _tcpconn_free(struct tcp_connection* c)
1258 1258
 {
1259
-#ifdef TCP_BUF_WRITE
1259
+#ifdef TCP_ASYNC
1260 1260
 	if (unlikely(_wbufq_non_empty(c)))
1261 1261
 		_wbufq_destroy(&c->wbuf_q);
1262 1262
 #endif
... ...
@@ -1621,9 +1621,9 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
1621 1621
 	int n;
1622 1622
 	int do_close_fd;
1623 1623
 	ticks_t con_lifetime;
1624
-#ifdef TCP_BUF_WRITE
1624
+#ifdef TCP_ASYNC
1625 1625
 	int enable_write_watch;
1626
-#endif /* TCP_BUF_WRITE */
1626
+#endif /* TCP_ASYNC */
1627 1627
 #ifdef TCP_FD_CACHE
1628 1628
 	struct fd_cache_entry* fd_cache_e;
1629 1629
 	int use_fd_cache;
... ...
@@ -1677,9 +1677,9 @@ no_id:
1677 1677
 						break;
1678 1678
 				}
1679 1679
 			}
1680
-#if defined(TCP_CONNECT_WAIT) && defined(TCP_BUF_WRITE)
1680
+#if defined(TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
1681 1681
 			if (likely(cfg_get(tcp, tcp_cfg, tcp_connect_wait) && 
1682
-						cfg_get(tcp, tcp_cfg, tcp_buf_write) )){
1682
+						cfg_get(tcp, tcp_cfg, async) )){
1683 1683
 				if (unlikely(*tcp_connections_no >=
1684 1684
 								cfg_get(tcp, tcp_cfg, max_connections))){
1685 1685
 					LOG(L_ERR, "ERROR: tcp_send %s: maximum number of"
... ...
@@ -1795,7 +1795,7 @@ no_id:
1795 1795
 				}
1796 1796
 				goto end;
1797 1797
 			}
1798
-#endif /* TCP_CONNECT_WAIT  && TCP_BUF_WRITE */
1798
+#endif /* TCP_CONNECT_WAIT  && TCP_ASYNC */
1799 1799
 			if (unlikely((c=tcpconn_connect(&dst->to, from, dst->proto))==0)){
1800 1800
 				LOG(L_ERR, "ERROR: tcp_send %s: connect failed\n",
1801 1801
 								su2a(&dst->to, sizeof(dst->to)));
... ...
@@ -1824,9 +1824,9 @@ no_id:
1824 1824
 			goto send_it;
1825 1825
 		}
1826 1826
 get_fd:
1827
-#ifdef TCP_BUF_WRITE
1827
+#ifdef TCP_ASYNC
1828 1828
 		/* if data is already queued, we don't need the fd any more */
1829
-		if (unlikely(cfg_get(tcp, tcp_cfg, tcp_buf_write) &&
1829
+		if (unlikely(cfg_get(tcp, tcp_cfg, async) &&
1830 1830
 						(_wbufq_non_empty(c)
1831 1831
 #ifdef TCP_CONNECT_WAIT
1832 1832
 												|| (c->state==S_CONN_PENDING)
... ...
@@ -1851,7 +1851,7 @@ get_fd:
1851 1851
 				}
1852 1852
 			lock_release(&c->write_lock);
1853 1853
 		}
1854
-#endif /* TCP_BUF_WRITE */
1854
+#endif /* TCP_ASYNC */
1855 1855
 		/* check if this is not the same reader process holding
1856 1856
 		 *  c  and if so send directly on c->fd */
1857 1857
 		if (c->reader_pid==my_pid()){
... ...
@@ -1909,8 +1909,8 @@ get_fd:
1909 1909
 send_it:
1910 1910
 	DBG("tcp_send: sending...\n");
1911 1911
 	lock_get(&c->write_lock);
1912
-#ifdef TCP_BUF_WRITE
1913
-	if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
1912
+#ifdef TCP_ASYNC
1913
+	if (likely(cfg_get(tcp, tcp_cfg, async))){
1914 1914
 		if (_wbufq_non_empty(c)
1915 1915
 #ifdef TCP_CONNECT_WAIT
1916 1916
 			|| (c->state==S_CONN_PENDING) 
... ...
@@ -1927,7 +1927,7 @@ send_it:
1927 1927
 		}
1928 1928
 		n=_tcpconn_write_nb(fd, c, buf, len);
1929 1929
 	}else{
1930
-#endif /* TCP_BUF_WRITE */
1930
+#endif /* TCP_ASYNC */
1931 1931
 #ifdef USE_TLS
1932 1932
 	if (c->type==PROTO_TLS)
1933 1933
 		n=tls_blocking_write(c, fd, buf, len);
... ...
@@ -1936,17 +1936,17 @@ send_it:
1936 1936
 		/* n=tcp_blocking_write(c, fd, buf, len); */
1937 1937
 		n=tsend_stream(fd, buf, len,
1938 1938
 							cfg_get(tcp, tcp_cfg, send_timeout_s)*1000);
1939
-#ifdef TCP_BUF_WRITE
1939
+#ifdef TCP_ASYNC
1940 1940
 	}
1941
-#else /* ! TCP_BUF_WRITE */
1941
+#else /* ! TCP_ASYNC */
1942 1942
 	lock_release(&c->write_lock);
1943
-#endif /* TCP_BUF_WRITE */
1943
+#endif /* TCP_ASYNC */
1944 1944
 	
1945 1945
 	DBG("tcp_send: after real write: c= %p n=%d fd=%d\n",c, n, fd);
1946 1946
 	DBG("tcp_send: buf=\n%.*s\n", (int)len, buf);
1947 1947
 	if (unlikely(n<(int)len)){
1948
-#ifdef TCP_BUF_WRITE
1949
-		if (cfg_get(tcp, tcp_cfg, tcp_buf_write) && 
1948
+#ifdef TCP_ASYNC
1949
+		if (cfg_get(tcp, tcp_cfg, async) && 
1950 1950
 				((n>=0) || errno==EAGAIN || errno==EWOULDBLOCK)){
1951 1951
 			enable_write_watch=_wbufq_empty(c);
1952 1952
 			if (n<0) n=0;
... ...
@@ -1971,7 +1971,7 @@ send_it:
1971 1971
 		}else{
1972 1972
 			lock_release(&c->write_lock);
1973 1973
 		}
1974
-#endif /* TCP_BUF_WRITE */
1974
+#endif /* TCP_ASYNC */
1975 1975
 #ifdef USE_DST_BLACKLIST
1976 1976
 		if (cfg_get(core, core_cfg, use_dst_blacklist))
1977 1977
 			switch(errno){
... ...
@@ -1990,9 +1990,9 @@ send_it:
1990 1990
 					"\n", c, ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port,
1991 1991
 					su2a(&c->rcv.src_su, sizeof(c->rcv.src_su)),
1992 1992
 					strerror(errno), errno);
1993
-#ifdef TCP_BUF_WRITE
1993
+#ifdef TCP_ASYNC
1994 1994
 error:
1995
-#endif /* TCP_BUF_WRITE */
1995
+#endif /* TCP_ASYNC */
1996 1996
 		/* error on the connection , mark it as bad and set 0 timeout */
1997 1997
 		c->state=S_CONN_BAD;
1998 1998
 		c->timeout=get_ticks_raw();
... ...
@@ -2021,13 +2021,13 @@ error:
2021 2021
 		return n; /* error return, no tcpconn_put */
2022 2022
 	}
2023 2023
 	
2024
-#ifdef TCP_BUF_WRITE
2024
+#ifdef TCP_ASYNC
2025 2025
 	lock_release(&c->write_lock);
2026
-	if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
2026
+	if (likely(cfg_get(tcp, tcp_cfg, async))){
2027 2027
 		if (unlikely(c->state==S_CONN_CONNECT))
2028 2028
 			c->state=S_CONN_OK;
2029 2029
 	}
2030
-#endif /* TCP_BUF_WRITE */
2030
+#endif /* TCP_ASYNC */
2031 2031
 end:
2032 2032
 #ifdef TCP_FD_CACHE
2033 2033
 	if (unlikely((fd_cache_e==0) && use_fd_cache)){
... ...
@@ -2368,7 +2368,7 @@ inline static int tcpconn_try_unhash(struct tcp_connection* tcpconn)
2368 2368
 				TCPCONN_UNLOCK;
2369 2369
 				return 0;
2370 2370
 			}
2371
-#ifdef TCP_BUF_WRITE
2371
+#ifdef TCP_ASYNC
2372 2372
 		/* empty possible write buffers (optional) */
2373 2373
 		if (unlikely(_wbufq_non_empty(tcpconn))){
2374 2374
 			lock_get(&tcpconn->write_lock);
... ...
@@ -2377,7 +2377,7 @@ inline static int tcpconn_try_unhash(struct tcp_connection* tcpconn)
2377 2377
 					_wbufq_destroy(&tcpconn->wbuf_q);
2378 2378
 			lock_release(&tcpconn->write_lock);
2379 2379
 		}
2380
-#endif /* TCP_BUF_WRITE */
2380
+#endif /* TCP_ASYNC */
2381 2381
 		return 1;
2382 2382
 	}
2383 2383
 	return 0;
... ...
@@ -2508,7 +2508,7 @@ inline static void send_fd_queue_run(struct tcp_send_fd_q* q)
2508 2508
 						   p->unix_sock, (long)(p-&q->data[0]), p->retries,
2509 2509
 						   p->tcp_conn, p->tcp_conn->s, errno,
2510 2510
 						   strerror(errno));
2511
-#ifdef TCP_BUF_WRITE
2511
+#ifdef TCP_ASYNC
2512 2512
 				if (p->tcp_conn->flags & F_CONN_WRITE_W){
2513 2513
 					io_watch_del(&io_h, p->tcp_conn->s, -1, IO_FD_CLOSING);
2514 2514
 					p->tcp_conn->flags &=~F_CONN_WRITE_W;
... ...
@@ -2642,12 +2642,12 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
2642 2642
 				break;
2643 2643
 			}
2644 2644
 			if (unlikely(tcpconn->state==S_CONN_BAD)){ 
2645
-#ifdef TCP_BUF_WRITE
2645
+#ifdef TCP_ASYNC
2646 2646
 				if (unlikely(tcpconn->flags & F_CONN_WRITE_W)){
2647 2647
 					io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
2648 2648
 					tcpconn->flags &= ~F_CONN_WRITE_W;
2649 2649
 				}
2650
-#endif /* TCP_BUF_WRITE */
2650
+#endif /* TCP_ASYNC */
2651 2651
 				if (tcpconn_try_unhash(tcpconn))
2652 2652
 					tcpconn_put_destroy(tcpconn);
2653 2653
 				break;
... ...
@@ -2657,8 +2657,8 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
2657 2657
 			con_lifetime=cfg_get(tcp, tcp_cfg, con_lifetime);
2658 2658
 			tcpconn->timeout=t+con_lifetime;
2659 2659
 			crt_timeout=con_lifetime;
2660
-#ifdef TCP_BUF_WRITE
2661
-			if (unlikely(cfg_get(tcp, tcp_cfg, tcp_buf_write) && 
2660
+#ifdef TCP_ASYNC
2661
+			if (unlikely(cfg_get(tcp, tcp_cfg, async) && 
2662 2662
 							_wbufq_non_empty(tcpconn) )){
2663 2663
 				if (unlikely(TICKS_GE(t, tcpconn->wbuf_q.wr_timeout))){
2664 2664
 					DBG("handle_tcp_child: wr. timeout on CONN_RELEASE for %p "
... ...
@@ -2685,7 +2685,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
2685 2685
 											tcpconn->wbuf_q.wr_timeout-t);
2686 2686
 				}
2687 2687
 			}
2688
-#endif /* TCP_BUF_WRITE */
2688
+#endif /* TCP_ASYNC */
2689 2689
 			/* re-activate the timer */
2690 2690
 			tcpconn->timer.f=tcpconn_main_timeout;
2691 2691
 			local_timer_reinit(&tcpconn->timer);
... ...
@@ -2693,22 +2693,22 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
2693 2693
 			/* must be after the de-ref*/
2694 2694
 			tcpconn->flags|=(F_CONN_MAIN_TIMER|F_CONN_READ_W|F_CONN_WANTS_RD);
2695 2695
 			tcpconn->flags&=~(F_CONN_READER|F_CONN_OOB_DATA);
2696
-#ifdef TCP_BUF_WRITE
2696
+#ifdef TCP_ASYNC
2697 2697
 			if (unlikely(tcpconn->flags & F_CONN_WRITE_W))
2698 2698
 				n=io_watch_chg(&io_h, tcpconn->s, POLLIN| POLLOUT, -1);
2699 2699
 			else
2700
-#endif /* TCP_BUF_WRITE */
2700
+#endif /* TCP_ASYNC */
2701 2701
 				n=io_watch_add(&io_h, tcpconn->s, POLLIN, F_TCPCONN, tcpconn);
2702 2702
 			if (unlikely(n<0)){
2703 2703
 				LOG(L_CRIT, "ERROR: tcp_main: handle_tcp_child: failed to add"
2704 2704
 						" new socket to the fd list\n");
2705 2705
 				tcpconn->flags&=~F_CONN_READ_W;
2706
-#ifdef TCP_BUF_WRITE
2706
+#ifdef TCP_ASYNC
2707 2707
 				if (unlikely(tcpconn->flags & F_CONN_WRITE_W)){
2708 2708
 					io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
2709 2709
 					tcpconn->flags&=~F_CONN_WRITE_W;
2710 2710
 				}
2711
-#endif /* TCP_BUF_WRITE */
2711
+#endif /* TCP_ASYNC */
2712 2712
 				if (tcpconn_try_unhash(tcpconn));
2713 2713
 					tcpconn_put_destroy(tcpconn);
2714 2714
 				break;
... ...
@@ -2725,12 +2725,12 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
2725 2725
 				 if (tcpconn->s!=-1)
2726 2726
 					io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
2727 2727
 				*/
2728
-#ifdef TCP_BUF_WRITE
2728
+#ifdef TCP_ASYNC
2729 2729
 				if ((tcpconn->flags & F_CONN_WRITE_W) && (tcpconn->s!=-1)){
2730 2730
 					io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
2731 2731
 					tcpconn->flags&=~F_CONN_WRITE_W;
2732 2732
 				}
2733
-#endif /* TCP_BUF_WRITE */
2733
+#endif /* TCP_ASYNC */
2734 2734
 				if (tcpconn_try_unhash(tcpconn))
2735 2735
 					tcpconn_put(tcpconn);
2736 2736
 				tcpconn_put_destroy(tcpconn); /* deref & delete if refcnt==0 */
... ...
@@ -2772,9 +2772,9 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
2772 2772
 	int flags;
2773 2773
 	ticks_t t;
2774 2774
 	ticks_t con_lifetime;
2775
-#ifdef TCP_BUF_WRITE
2775
+#ifdef TCP_ASYNC
2776 2776
 	ticks_t nxt_timeout;
2777
-#endif /* TCP_BUF_WRITE */
2777
+#endif /* TCP_ASYNC */
2778 2778
 	
2779 2779
 	ret=-1;
2780 2780
 	if (unlikely(p->unix_sock<=0)){
... ...
@@ -2887,22 +2887,22 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
2887 2887
 			local_timer_add(&tcp_main_ltimer, &tcpconn->timer, 
2888 2888
 								con_lifetime, t);
2889 2889
 			tcpconn->flags|=(F_CONN_MAIN_TIMER|F_CONN_READ_W|F_CONN_WANTS_RD)
2890
-#ifdef TCP_BUF_WRITE
2890
+#ifdef TCP_ASYNC
2891 2891
 					/* not used for now, the connection is sent to tcp_main
2892 2892
 					 * before knowing whether we can write on it or we should 
2893 2893
 					 * wait */
2894 2894
 							| (((int)!(tcpconn->flags & F_CONN_WANTS_WR)-1)& 
2895 2895
 								F_CONN_WRITE_W)
2896
-#endif /* TCP_BUF_WRITE */
2896
+#endif /* TCP_ASYNC */
2897 2897
 				;
2898 2898
 			tcpconn->flags&=~F_CONN_FD_CLOSED;
2899 2899
 			flags=POLLIN 
2900
-#ifdef TCP_BUF_WRITE
2900
+#ifdef TCP_ASYNC
2901 2901
 					/* not used for now, the connection is sent to tcp_main
2902 2902
 					 * before knowing if we can write on it or we should 
2903 2903
 					 * wait */
2904 2904
 					| (((int)!(tcpconn->flags & F_CONN_WANTS_WR)-1) & POLLOUT)
2905
-#endif /* TCP_BUF_WRITE */
2905
+#endif /* TCP_ASYNC */
2906 2906
 					;
2907 2907
 			if (unlikely(
2908 2908
 					io_watch_add(&io_h, tcpconn->s, flags,
... ...
@@ -2914,7 +2914,7 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
2914 2914
 				tcpconn_put_destroy(tcpconn);
2915 2915
 			}
2916 2916
 			break;
2917
-#ifdef TCP_BUF_WRITE
2917
+#ifdef TCP_ASYNC
2918 2918
 		case CONN_QUEUED_WRITE:
2919 2919
 			/* received only if the wr. queue is empty and a write finishes
2920 2920
 			 * with EAGAIN (common after connect())
... ...
@@ -3049,7 +3049,7 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
3049 3049
 			}
3050 3050
 			break;
3051 3051
 #endif /* TCP_CONNECT_WAIT */
3052
-#endif /* TCP_BUF_WRITE */
3052
+#endif /* TCP_ASYNC */
3053 3053
 		default:
3054 3054
 			LOG(L_CRIT, "BUG: handle_ser_child: unknown cmd %d\n", cmd);
3055 3055
 	}
... ...
@@ -3253,10 +3253,10 @@ static inline int handle_new_connect(struct socket_info* si)
3253 3253
 inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev, 
3254 3254
 										int fd_i)
3255 3255
 {
3256
-#ifdef TCP_BUF_WRITE
3256
+#ifdef TCP_ASYNC
3257 3257
 	int empty_q;
3258 3258
 	int bytes;
3259
-#endif /* TCP_BUF_WRITE */
3259
+#endif /* TCP_ASYNC */
3260 3260
 	/*  is refcnt!=0 really necessary? 
3261 3261
 	 *  No, in fact it's a bug: I can have the following situation: a send only
3262 3262
 	 *   tcp connection used by n processes simultaneously => refcnt = n. In 
... ...
@@ -3276,7 +3276,7 @@ inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev,
3276 3276
 #endif
3277 3277
 	/* pass it to child, so remove it from the io watch list  and the local
3278 3278
 	 *  timer */
3279
-#ifdef TCP_BUF_WRITE
3279
+#ifdef TCP_ASYNC
3280 3280
 	empty_q=0; /* warning fix */
3281 3281
 	if (unlikely((ev & (POLLOUT|POLLERR|POLLHUP)) &&
3282 3282
 					(tcpconn->flags & F_CONN_WRITE_W))){
... ...
@@ -3351,14 +3351,14 @@ inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev,
3351 3351
 		}else
3352 3352
 #else
3353 3353
 	{
3354
-#endif /* TCP_BUF_WRITE */
3354
+#endif /* TCP_ASYNC */
3355 3355
 			if (unlikely(io_watch_del(&io_h, tcpconn->s, fd_i, 0)==-1)){
3356 3356
 				LOG(L_ERR, "ERROR: handle_tcpconn_ev: io_watch_del(3)"
3357 3357
 							" failed:" " for %p, fd %d\n",
3358 3358
 							tcpconn, tcpconn->s);
3359 3359
 				goto error;
3360 3360
 			}
3361
-#ifdef TCP_BUF_WRITE
3361
+#ifdef TCP_ASYNC
3362 3362
 send_to_child:
3363 3363
 #endif
3364 3364
 		DBG("tcp: DBG: sendig to child, events %x\n", ev);
... ...
@@ -3376,7 +3376,7 @@ send_to_child:
3376 3376
 		if (unlikely(send2child(tcpconn)<0)){
3377 3377
 			LOG(L_ERR,"ERROR: handle_tcpconn_ev: no children available\n");
3378 3378
 			tcpconn->flags&=~F_CONN_READER;
3379
-#ifdef TCP_BUF_WRITE
3379
+#ifdef TCP_ASYNC
3380 3380
 			if (tcpconn->flags & F_CONN_WRITE_W){
3381 3381
 				if (unlikely(io_watch_del(&io_h, tcpconn->s, fd_i, 0)<0)){
3382 3382
 					LOG(L_ERR, "ERROR: handle_tcpconn_ev: io_watch_del(4)"
... ...
@@ -3385,7 +3385,7 @@ send_to_child:
3385 3385
 				}
3386 3386
 				tcpconn->flags&=~F_CONN_WRITE_W;
3387 3387
 			}
3388
-#endif /* TCP_BUF_WRITE */
3388
+#endif /* TCP_ASYNC */
3389 3389
 			tcpconn_put(tcpconn);
3390 3390
 			tcpconn_try_unhash(tcpconn); 
3391 3391
 			tcpconn_put_destroy(tcpconn); /* because of the tcpconn_ref() */
... ...
@@ -3458,14 +3458,14 @@ static ticks_t tcpconn_main_timeout(ticks_t t, struct timer_ln* tl, void* data)
3458 3458
 	c=(struct tcp_connection*)data; 
3459 3459
 	/* or (struct tcp...*)(tl-offset(c->timer)) */
3460 3460
 	
3461
-#ifdef TCP_BUF_WRITE
3461
+#ifdef TCP_ASYNC
3462 3462
 	DBG( "tcp_main: entering timer for %p (ticks=%d, timeout=%d (%d s), "
3463 3463
 			"wr_timeout=%d (%d s)), write queue: %d bytes\n",
3464 3464
 			c, t, c->timeout, TICKS_TO_S(c->timeout-t),
3465 3465
 			c->wbuf_q.wr_timeout, TICKS_TO_S(c->wbuf_q.wr_timeout-t),
3466 3466
 			c->wbuf_q.queued);
3467 3467
 	
3468
-	tcp_async=cfg_get(tcp, tcp_cfg, tcp_buf_write);
3468
+	tcp_async=cfg_get(tcp, tcp_cfg, async);
3469 3469
 	if (likely(TICKS_LT(t, c->timeout) && ( !tcp_async | _wbufq_empty(c) |
3470 3470
 					TICKS_LT(t, c->wbuf_q.wr_timeout)) )){
3471 3471
 		if (unlikely(tcp_async && _wbufq_non_empty(c)))
... ...
@@ -3482,12 +3482,12 @@ static ticks_t tcpconn_main_timeout(ticks_t t, struct timer_ln* tl, void* data)
3482 3482
 										BLST_ERR_SEND,
3483 3483
 								c->rcv.proto, &c->rcv.src_su, 0);
3484 3484
 #endif /* USE_DST_BLACKLIST */
3485
-#else /* ! TCP_BUF_WRITE */
3485
+#else /* ! TCP_ASYNC */
3486 3486
 	if (TICKS_LT(t, c->timeout)){
3487 3487
 		/* timeout extended, exit */
3488 3488
 		return (ticks_t)(c->timeout - t);
3489 3489
 	}
3490
-#endif /* TCP_BUF_WRITE */
3490
+#endif /* TCP_ASYNC */
3491 3491
 	DBG("tcp_main: timeout for %p\n", c);
3492 3492
 	if (likely(c->flags & F_CONN_HASHED)){
3493 3493
 		c->flags&=~(F_CONN_HASHED|F_CONN_MAIN_TIMER);
... ...
@@ -3764,12 +3764,12 @@ void destroy_tcp()
3764 3764
 			shm_free(tcp_connections_no);
3765 3765
 			tcp_connections_no=0;
3766 3766
 		}
3767
-#ifdef TCP_BUF_WRITE
3767
+#ifdef TCP_ASYNC
3768 3768
 		if (tcp_total_wq){
3769 3769
 			shm_free(tcp_total_wq);
3770 3770
 			tcp_total_wq=0;
3771 3771
 		}
3772
-#endif /* TCP_BUF_WRITE */
3772
+#endif /* TCP_ASYNC */
3773 3773
 		if (connection_id){
3774 3774
 			shm_free(connection_id);
3775 3775
 			connection_id=0;
... ...
@@ -3826,13 +3826,13 @@ int init_tcp()
3826 3826
 		goto error;
3827 3827
 	}
3828 3828
 	*connection_id=1;
3829
-#ifdef TCP_BUF_WRITE
3829
+#ifdef TCP_ASYNC
3830 3830
 	tcp_total_wq=shm_malloc(sizeof(*tcp_total_wq));
3831 3831
 	if (tcp_total_wq==0){
3832 3832
 		LOG(L_CRIT, "ERROR: init_tcp: could not alloc globals\n");
3833 3833
 		goto error;
3834 3834
 	}
3835
-#endif /* TCP_BUF_WRITE */
3835
+#endif /* TCP_ASYNC */
3836 3836
 	/* alloc hashtables*/
3837 3837
 	tcpconn_aliases_hash=(struct tcp_conn_alias**)
3838 3838
 			shm_malloc(TCP_ALIAS_HASH_SIZE* sizeof(struct tcp_conn_alias*));
... ...
@@ -3981,11 +3981,11 @@ void tcp_get_info(struct tcp_gen_info *ti)
3981 3981
 	ti->tcp_readers=tcp_children_no;
3982 3982
 	ti->tcp_max_connections=tcp_max_connections;
3983 3983
 	ti->tcp_connections_no=*tcp_connections_no;
3984
-#ifdef TCP_BUF_WRITE
3984
+#ifdef TCP_ASYNC
3985 3985
 	ti->tcp_write_queued=*tcp_total_wq;
3986 3986
 #else
3987 3987
 	ti->tcp_write_queued=0;
3988
-#endif /* TCP_BUF_WRITE */
3988
+#endif /* TCP_ASYNC */
3989 3989
 }
3990 3990
 
3991 3991
 #endif
... ...
@@ -41,7 +41,7 @@ struct cfg_group_tcp tcp_default_cfg;
41 41
 {
42 42
 	1, /* fd_cache, default on */
43 43
 	/* tcp async options */
44
-	0, /* tcp_buf_write / tcp_async, default off */
44
+	0, /* async / tcp_async, default off */
45 45
 	1, /* tcp_connect_wait - depends on tcp_async */
46 46
 	32*1024, /* tcpconn_wq_max - max. write queue len per connection (32k) */
47 47
 	10*1024*1024, /* tcp_wq_max - max.  overall queued bytes  (10MB)*/
... ...
@@ -147,15 +147,15 @@ void init_tcp_options()
147 147
 	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
148 148
 	tcp_default_cfg.con_lifetime_s=DEFAULT_TCP_CONNECTION_LIFETIME_S;
149 149
 	tcp_default_cfg.max_connections=tcp_max_connections;
150
-#ifdef TCP_BUF_WRITE
151
-	tcp_default_cfg.tcp_buf_write=0;
150
+#ifdef TCP_ASYNC
151
+	tcp_default_cfg.async=1;
152 152
 	tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */
153 153
 	tcp_default_cfg.tcp_wq_max=10*1024*1024; /* 10 MB */
154 154
 	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
155 155
 #ifdef TCP_CONNECT_WAIT
156 156
 	tcp_default_cfg.tcp_connect_wait=1;
157 157
 #endif /* TCP_CONNECT_WAIT */
158
-#endif /* TCP_BUF_WRITE */
158
+#endif /* TCP_ASYNC */
159 159
 #ifdef TCP_FD_CACHE
160 160
 	tcp_default_cfg.fd_cache=1;
161 161
 #endif
... ...
@@ -229,9 +229,9 @@ static int fix_send_to(void* cfg_h, str* name, void** val)
229 229
 	fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
230 230
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
231 231
 	*val=(void*)(long)v;
232
-#ifdef TCP_BUF_WRITE
232
+#ifdef TCP_ASYNC
233 233
 	((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
234
-#endif /* TCP_BUF_WRITE */
234
+#endif /* TCP_ASYNC */
235 235
 	return 0;
236 236
 }
237 237
 
... ...
@@ -244,9 +244,9 @@ static int fix_con_lt(void* cfg_h, str* name, void** val)
244 244
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
245 245
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
246 246
 	*val=(void*)(long)v;
247
-#ifdef TCP_BUF_WRITE
247
+#ifdef TCP_ASYNC
248 248
 	((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
249
-#endif /* TCP_BUF_WRITE */
249
+#endif /* TCP_ASYNC */
250 250
 	return 0;
251 251
 }
252 252
 
... ...
@@ -273,19 +273,17 @@ void tcp_options_check()
273 273
 	W_OPT_NC(defer_accept);
274 274
 #endif
275 275
 
276
-#ifndef TCP_BUF_WRITE
277
-	W_OPT_NC(tcp_buf_write);
276
+#ifndef TCP_ASYNC
277
+	W_OPT_NC(async);
278 278
 	W_OPT_NC(tcpconn_wq_max);
279 279
 	W_OPT_NC(tcp_wq_max);
280 280
 	W_OPT_NC(tcp_wq_timeout);
281
-#endif /* TCP_BUF_WRITE */
281
+#endif /* TCP_ASYNC */
282 282
 #ifndef TCP_CONNECT_WAIT
283 283
 	W_OPT_NC(tcp_connect_wait);
284 284
 #endif /* TCP_CONNECT_WAIT */
285 285
 	
286
-	if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.tcp_buf_write){
287
-		WARN("tcp_options: tcp_connect_wait depends on tcp_buf_write, "
288
-				" disabling...\n");
286
+	if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.async){
289 287
 		tcp_default_cfg.tcp_connect_wait=0;
290 288
 	}
291 289
 	
... ...
@@ -328,9 +326,9 @@ void tcp_options_check()
328 328
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
329 329
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
330 330
 	/* compute timeout in ticks */
331
-#ifdef TCP_BUF_WRITE
331
+#ifdef TCP_ASYNC
332 332
 	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
333
-#endif /* TCP_BUF_WRITE */
333
+#endif /* TCP_ASYNC */
334 334
 	tcp_default_cfg.con_lifetime=S_TO_TICKS(tcp_default_cfg.con_lifetime_s);
335 335
 	tcp_default_cfg.max_connections=tcp_max_connections;
336 336
 }
... ...
@@ -28,17 +28,17 @@
28 28
 
29 29
 #ifdef USE_TCP
30 30
 
31
-#ifndef NO_TCP_BUF_WRITE
32
-#define TCP_BUF_WRITE /* enabled buffered writing */
33
-#endif 
31
+#ifndef NO_TCP_ASYNC
32
+#define TCP_ASYNC /* enabled async mode */
33
+#endif
34 34
 
35
-#if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_BUF_WRITE)
35
+#if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
36 36
 #define TCP_CONNECT_WAIT /* enable pending connects support */
37 37
 #endif
38 38
 
39
-#if defined(TCP_CONNECT_WAIT) && !defined(TCP_BUF_WRITE)
40
-/* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_BUF_WRITE */
41
-#warning "disabling TCP_CONNECT_WAIT because TCP_BUF_WRITE is not defined"
39
+#if defined(TCP_CONNECT_WAIT) && !defined(TCP_ASYNC)
40
+/* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_ASYNC */
41
+#warning "disabling TCP_CONNECT_WAIT because TCP_ASYNC is not defined"
42 42
 #undef TCP_CONNECT_WAIT
43 43
 #endif
44 44
 
... ...
@@ -117,8 +117,8 @@ struct cfg_group_tcp{
117 117
 	int max_connections;
118 118
 	int fd_cache; /* on /off */
119 119
 	/* tcp async options */
120
-	int tcp_buf_write; /* on / off */
121
-	int tcp_connect_wait; /* on / off, depends on tcp_buf_write */
120
+	int async; /* on / off */
121
+	int tcp_connect_wait; /* on / off, depends on async */
122 122
 	unsigned int tcpconn_wq_max; /* maximum queue len per connection */
123 123
 	unsigned int tcp_wq_max; /* maximum overall queued bytes */
124 124