tcp: async mode on by default
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 5 Mar 2009 17:21:11 +0000 (17:21 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 5 Mar 2009 17:21:11 +0000 (17:21 +0000)
- 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

NEWS
cfg.y
core_cmd.c
tcp_conn.h
tcp_main.c
tcp_options.c
tcp_options.h

diff --git a/NEWS b/NEWS
index f3cbfb3..ad12ca4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -273,10 +273,10 @@ new config variables:
      will be cached inside the process calling tcp_send (performance increase
      for sending over tcp at the cost of slightly slower connection closing and
      extra FDs kept open)
-  tcp_async = yes | no (default no) - if enabled all the tcp  writes that 
+  tcp_async = yes | no (default yes) - if enabled all the tcp  writes that 
      would block / wait for connect to finish, will be queued and attempted
      latter (see also tcp_conn_wq_max and tcp_wq_max).
-  tcp_buf_write = synonim for tcp_async
+  tcp_buf_write = obsoleted synonim for tcp_async
   tcp_conn_wq_max = bytes (default 32 K) - maximum bytes queued for write 
      allowed per connection. Attempting to queue more bytes would result
      in an error and in the connection being closed (too slow). If 
diff --git a/cfg.y b/cfg.y
index c26af50..1523af1 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -873,7 +873,7 @@ assign_stm:
        | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
        | TCP_OPT_BUF_WRITE EQUAL NUMBER {
                #ifdef USE_TCP
-                       tcp_default_cfg.tcp_buf_write=$3;
+                       tcp_default_cfg.async=$3;
                #else
                        warn("tcp support not compiled in");
                #endif
index ccac004..d2d7aed 100644 (file)
@@ -571,7 +571,7 @@ static void core_tcp_options(rpc_t* rpc, void* c)
                        "connection_lifetime",  t.con_lifetime_s,
                        "max_connections(soft)", t.max_connections,
                        "fd_cache",             t.fd_cache,
-                       "async",                t.tcp_buf_write,
+                       "async",                t.async,
                        "connect_wait", t.tcp_connect_wait,
                        "conn_wq_max",  t.tcpconn_wq_max,
                        "wq_max",               t.tcp_wq_max,
index 81ce224..5a9e6d4 100644 (file)
@@ -132,7 +132,7 @@ struct tcp_conn_alias{
 };
 
 
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        struct tcp_wbuffer{
                struct tcp_wbuffer* next;
                unsigned int b_size;
@@ -174,7 +174,7 @@ struct tcp_connection{
        struct tcp_connection* c_prev;
        struct tcp_conn_alias con_aliases[TCP_CON_MAX_ALIASES];
        int aliases; /* aliases number, at least 1 */
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        struct tcp_wbuffer_queue wbuf_q;
 #endif
 };
index a2bf5d0..86fedb7 100644 (file)
 #define TCPCONN_TIMEOUT_MIN_RUN 1  /* once per tick */
 #define TCPCONN_WAIT_TIMEOUT 1 /* 1 tick */
 
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
 #define TCP_WBUF_SIZE  1024 /* FIXME: after debugging switch to 16-32k */
 static unsigned int* tcp_total_wq=0;
 #endif
@@ -598,7 +598,7 @@ inline static int _tcpconn_write_nb(int fd, struct tcp_connection* c,
                                                                        char* buf, int len);
 
 
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
 
 
 /* unsafe version */
@@ -841,7 +841,7 @@ inline static int wbufq_run(int fd, struct tcp_connection* c, int* empty)
        return ret;
 }
 
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 
 
 
@@ -995,9 +995,9 @@ inline static int tcp_do_connect(   union sockaddr_union* server,
        union sockaddr_union my_name;
        socklen_t my_name_len;
        struct ip_addr ip;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        int n;
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 
        s=socket(AF2PF(server->s.sa_family), SOCK_STREAM, 0);
        if (unlikely(s==-1)){
@@ -1017,8 +1017,8 @@ inline static int tcp_do_connect( union sockaddr_union* server,
                                        strerror(errno), errno);
        }
        *state=S_CONN_OK;
-#ifdef TCP_BUF_WRITE
-       if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
+#ifdef TCP_ASYNC
+       if (likely(cfg_get(tcp, tcp_cfg, async))){
 again:
                n=connect(s, &server->s, sockaddru_len(*server));
                if (unlikely(n==-1)){
@@ -1046,16 +1046,16 @@ again:
                        }
                }
        }else{
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                if (tcp_blocking_connect(s, type, &server->s,
                                                                        sockaddru_len(*server))<0){
                        LOG(L_ERR, "ERROR: tcp_do_connect: tcp_blocking_connect %s"
                                                " failed\n", su2a(server, sizeof(*server)));
                        goto error;
                }
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        if (from){
                su2ip_addr(&ip, from);
                if (!ip_addr_any(&ip))
@@ -1256,7 +1256,7 @@ static inline void _tcpconn_detach(struct tcp_connection *c)
 
 static inline void _tcpconn_free(struct tcp_connection* c)
 {
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        if (unlikely(_wbufq_non_empty(c)))
                _wbufq_destroy(&c->wbuf_q);
 #endif
@@ -1621,9 +1621,9 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
        int n;
        int do_close_fd;
        ticks_t con_lifetime;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        int enable_write_watch;
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 #ifdef TCP_FD_CACHE
        struct fd_cache_entry* fd_cache_e;
        int use_fd_cache;
@@ -1677,9 +1677,9 @@ no_id:
                                                break;
                                }
                        }
-#if defined(TCP_CONNECT_WAIT) && defined(TCP_BUF_WRITE)
+#if defined(TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
                        if (likely(cfg_get(tcp, tcp_cfg, tcp_connect_wait) && 
-                                               cfg_get(tcp, tcp_cfg, tcp_buf_write) )){
+                                               cfg_get(tcp, tcp_cfg, async) )){
                                if (unlikely(*tcp_connections_no >=
                                                                cfg_get(tcp, tcp_cfg, max_connections))){
                                        LOG(L_ERR, "ERROR: tcp_send %s: maximum number of"
@@ -1795,7 +1795,7 @@ no_id:
                                }
                                goto end;
                        }
-#endif /* TCP_CONNECT_WAIT  && TCP_BUF_WRITE */
+#endif /* TCP_CONNECT_WAIT  && TCP_ASYNC */
                        if (unlikely((c=tcpconn_connect(&dst->to, from, dst->proto))==0)){
                                LOG(L_ERR, "ERROR: tcp_send %s: connect failed\n",
                                                                su2a(&dst->to, sizeof(dst->to)));
@@ -1824,9 +1824,9 @@ no_id:
                        goto send_it;
                }
 get_fd:
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                /* if data is already queued, we don't need the fd any more */
-               if (unlikely(cfg_get(tcp, tcp_cfg, tcp_buf_write) &&
+               if (unlikely(cfg_get(tcp, tcp_cfg, async) &&
                                                (_wbufq_non_empty(c)
 #ifdef TCP_CONNECT_WAIT
                                                                                                || (c->state==S_CONN_PENDING)
@@ -1851,7 +1851,7 @@ get_fd:
                                }
                        lock_release(&c->write_lock);
                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                /* check if this is not the same reader process holding
                 *  c  and if so send directly on c->fd */
                if (c->reader_pid==my_pid()){
@@ -1909,8 +1909,8 @@ get_fd:
 send_it:
        DBG("tcp_send: sending...\n");
        lock_get(&c->write_lock);
-#ifdef TCP_BUF_WRITE
-       if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
+#ifdef TCP_ASYNC
+       if (likely(cfg_get(tcp, tcp_cfg, async))){
                if (_wbufq_non_empty(c)
 #ifdef TCP_CONNECT_WAIT
                        || (c->state==S_CONN_PENDING) 
@@ -1927,7 +1927,7 @@ send_it:
                }
                n=_tcpconn_write_nb(fd, c, buf, len);
        }else{
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 #ifdef USE_TLS
        if (c->type==PROTO_TLS)
                n=tls_blocking_write(c, fd, buf, len);
@@ -1936,17 +1936,17 @@ send_it:
                /* n=tcp_blocking_write(c, fd, buf, len); */
                n=tsend_stream(fd, buf, len,
                                                        cfg_get(tcp, tcp_cfg, send_timeout_s)*1000);
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        }
-#else /* ! TCP_BUF_WRITE */
+#else /* ! TCP_ASYNC */
        lock_release(&c->write_lock);
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        
        DBG("tcp_send: after real write: c= %p n=%d fd=%d\n",c, n, fd);
        DBG("tcp_send: buf=\n%.*s\n", (int)len, buf);
        if (unlikely(n<(int)len)){
-#ifdef TCP_BUF_WRITE
-               if (cfg_get(tcp, tcp_cfg, tcp_buf_write) && 
+#ifdef TCP_ASYNC
+               if (cfg_get(tcp, tcp_cfg, async) && 
                                ((n>=0) || errno==EAGAIN || errno==EWOULDBLOCK)){
                        enable_write_watch=_wbufq_empty(c);
                        if (n<0) n=0;
@@ -1971,7 +1971,7 @@ send_it:
                }else{
                        lock_release(&c->write_lock);
                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 #ifdef USE_DST_BLACKLIST
                if (cfg_get(core, core_cfg, use_dst_blacklist))
                        switch(errno){
@@ -1990,9 +1990,9 @@ send_it:
                                        "\n", c, ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port,
                                        su2a(&c->rcv.src_su, sizeof(c->rcv.src_su)),
                                        strerror(errno), errno);
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
 error:
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                /* error on the connection , mark it as bad and set 0 timeout */
                c->state=S_CONN_BAD;
                c->timeout=get_ticks_raw();
@@ -2021,13 +2021,13 @@ error:
                return n; /* error return, no tcpconn_put */
        }
        
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        lock_release(&c->write_lock);
-       if (likely(cfg_get(tcp, tcp_cfg, tcp_buf_write))){
+       if (likely(cfg_get(tcp, tcp_cfg, async))){
                if (unlikely(c->state==S_CONN_CONNECT))
                        c->state=S_CONN_OK;
        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 end:
 #ifdef TCP_FD_CACHE
        if (unlikely((fd_cache_e==0) && use_fd_cache)){
@@ -2368,7 +2368,7 @@ inline static int tcpconn_try_unhash(struct tcp_connection* tcpconn)
                                TCPCONN_UNLOCK;
                                return 0;
                        }
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                /* empty possible write buffers (optional) */
                if (unlikely(_wbufq_non_empty(tcpconn))){
                        lock_get(&tcpconn->write_lock);
@@ -2377,7 +2377,7 @@ inline static int tcpconn_try_unhash(struct tcp_connection* tcpconn)
                                        _wbufq_destroy(&tcpconn->wbuf_q);
                        lock_release(&tcpconn->write_lock);
                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                return 1;
        }
        return 0;
@@ -2508,7 +2508,7 @@ inline static void send_fd_queue_run(struct tcp_send_fd_q* q)
                                                   p->unix_sock, (long)(p-&q->data[0]), p->retries,
                                                   p->tcp_conn, p->tcp_conn->s, errno,
                                                   strerror(errno));
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                if (p->tcp_conn->flags & F_CONN_WRITE_W){
                                        io_watch_del(&io_h, p->tcp_conn->s, -1, IO_FD_CLOSING);
                                        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)
                                break;
                        }
                        if (unlikely(tcpconn->state==S_CONN_BAD)){ 
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                if (unlikely(tcpconn->flags & F_CONN_WRITE_W)){
                                        io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
                                        tcpconn->flags &= ~F_CONN_WRITE_W;
                                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                if (tcpconn_try_unhash(tcpconn))
                                        tcpconn_put_destroy(tcpconn);
                                break;
@@ -2657,8 +2657,8 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
                        con_lifetime=cfg_get(tcp, tcp_cfg, con_lifetime);
                        tcpconn->timeout=t+con_lifetime;
                        crt_timeout=con_lifetime;
-#ifdef TCP_BUF_WRITE
-                       if (unlikely(cfg_get(tcp, tcp_cfg, tcp_buf_write) && 
+#ifdef TCP_ASYNC
+                       if (unlikely(cfg_get(tcp, tcp_cfg, async) && 
                                                        _wbufq_non_empty(tcpconn) )){
                                if (unlikely(TICKS_GE(t, tcpconn->wbuf_q.wr_timeout))){
                                        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)
                                                                                        tcpconn->wbuf_q.wr_timeout-t);
                                }
                        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                        /* re-activate the timer */
                        tcpconn->timer.f=tcpconn_main_timeout;
                        local_timer_reinit(&tcpconn->timer);
@@ -2693,22 +2693,22 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
                        /* must be after the de-ref*/
                        tcpconn->flags|=(F_CONN_MAIN_TIMER|F_CONN_READ_W|F_CONN_WANTS_RD);
                        tcpconn->flags&=~(F_CONN_READER|F_CONN_OOB_DATA);
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                        if (unlikely(tcpconn->flags & F_CONN_WRITE_W))
                                n=io_watch_chg(&io_h, tcpconn->s, POLLIN| POLLOUT, -1);
                        else
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                n=io_watch_add(&io_h, tcpconn->s, POLLIN, F_TCPCONN, tcpconn);
                        if (unlikely(n<0)){
                                LOG(L_CRIT, "ERROR: tcp_main: handle_tcp_child: failed to add"
                                                " new socket to the fd list\n");
                                tcpconn->flags&=~F_CONN_READ_W;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                if (unlikely(tcpconn->flags & F_CONN_WRITE_W)){
                                        io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
                                        tcpconn->flags&=~F_CONN_WRITE_W;
                                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                if (tcpconn_try_unhash(tcpconn));
                                        tcpconn_put_destroy(tcpconn);
                                break;
@@ -2725,12 +2725,12 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
                                 if (tcpconn->s!=-1)
                                        io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
                                */
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                if ((tcpconn->flags & F_CONN_WRITE_W) && (tcpconn->s!=-1)){
                                        io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
                                        tcpconn->flags&=~F_CONN_WRITE_W;
                                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                if (tcpconn_try_unhash(tcpconn))
                                        tcpconn_put(tcpconn);
                                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)
        int flags;
        ticks_t t;
        ticks_t con_lifetime;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        ticks_t nxt_timeout;
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        
        ret=-1;
        if (unlikely(p->unix_sock<=0)){
@@ -2887,22 +2887,22 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
                        local_timer_add(&tcp_main_ltimer, &tcpconn->timer, 
                                                                con_lifetime, t);
                        tcpconn->flags|=(F_CONN_MAIN_TIMER|F_CONN_READ_W|F_CONN_WANTS_RD)
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                        /* not used for now, the connection is sent to tcp_main
                                         * before knowing whether we can write on it or we should 
                                         * wait */
                                                        | (((int)!(tcpconn->flags & F_CONN_WANTS_WR)-1)& 
                                                                F_CONN_WRITE_W)
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                ;
                        tcpconn->flags&=~F_CONN_FD_CLOSED;
                        flags=POLLIN 
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                                        /* not used for now, the connection is sent to tcp_main
                                         * before knowing if we can write on it or we should 
                                         * wait */
                                        | (((int)!(tcpconn->flags & F_CONN_WANTS_WR)-1) & POLLOUT)
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                                        ;
                        if (unlikely(
                                        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)
                                tcpconn_put_destroy(tcpconn);
                        }
                        break;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                case CONN_QUEUED_WRITE:
                        /* received only if the wr. queue is empty and a write finishes
                         * with EAGAIN (common after connect())
@@ -3049,7 +3049,7 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
                        }
                        break;
 #endif /* TCP_CONNECT_WAIT */
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                default:
                        LOG(L_CRIT, "BUG: handle_ser_child: unknown cmd %d\n", cmd);
        }
@@ -3253,10 +3253,10 @@ static inline int handle_new_connect(struct socket_info* si)
 inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev, 
                                                                                int fd_i)
 {
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        int empty_q;
        int bytes;
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        /*  is refcnt!=0 really necessary? 
         *  No, in fact it's a bug: I can have the following situation: a send only
         *   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,
 #endif
        /* pass it to child, so remove it from the io watch list  and the local
         *  timer */
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        empty_q=0; /* warning fix */
        if (unlikely((ev & (POLLOUT|POLLERR|POLLHUP)) &&
                                        (tcpconn->flags & F_CONN_WRITE_W))){
@@ -3351,14 +3351,14 @@ inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev,
                }else
 #else
        {
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                        if (unlikely(io_watch_del(&io_h, tcpconn->s, fd_i, 0)==-1)){
                                LOG(L_ERR, "ERROR: handle_tcpconn_ev: io_watch_del(3)"
                                                        " failed:" " for %p, fd %d\n",
                                                        tcpconn, tcpconn->s);
                                goto error;
                        }
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
 send_to_child:
 #endif
                DBG("tcp: DBG: sendig to child, events %x\n", ev);
@@ -3376,7 +3376,7 @@ send_to_child:
                if (unlikely(send2child(tcpconn)<0)){
                        LOG(L_ERR,"ERROR: handle_tcpconn_ev: no children available\n");
                        tcpconn->flags&=~F_CONN_READER;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                        if (tcpconn->flags & F_CONN_WRITE_W){
                                if (unlikely(io_watch_del(&io_h, tcpconn->s, fd_i, 0)<0)){
                                        LOG(L_ERR, "ERROR: handle_tcpconn_ev: io_watch_del(4)"
@@ -3385,7 +3385,7 @@ send_to_child:
                                }
                                tcpconn->flags&=~F_CONN_WRITE_W;
                        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                        tcpconn_put(tcpconn);
                        tcpconn_try_unhash(tcpconn); 
                        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)
        c=(struct tcp_connection*)data; 
        /* or (struct tcp...*)(tl-offset(c->timer)) */
        
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        DBG( "tcp_main: entering timer for %p (ticks=%d, timeout=%d (%d s), "
                        "wr_timeout=%d (%d s)), write queue: %d bytes\n",
                        c, t, c->timeout, TICKS_TO_S(c->timeout-t),
                        c->wbuf_q.wr_timeout, TICKS_TO_S(c->wbuf_q.wr_timeout-t),
                        c->wbuf_q.queued);
        
-       tcp_async=cfg_get(tcp, tcp_cfg, tcp_buf_write);
+       tcp_async=cfg_get(tcp, tcp_cfg, async);
        if (likely(TICKS_LT(t, c->timeout) && ( !tcp_async | _wbufq_empty(c) |
                                        TICKS_LT(t, c->wbuf_q.wr_timeout)) )){
                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)
                                                                                BLST_ERR_SEND,
                                                                c->rcv.proto, &c->rcv.src_su, 0);
 #endif /* USE_DST_BLACKLIST */
-#else /* ! TCP_BUF_WRITE */
+#else /* ! TCP_ASYNC */
        if (TICKS_LT(t, c->timeout)){
                /* timeout extended, exit */
                return (ticks_t)(c->timeout - t);
        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        DBG("tcp_main: timeout for %p\n", c);
        if (likely(c->flags & F_CONN_HASHED)){
                c->flags&=~(F_CONN_HASHED|F_CONN_MAIN_TIMER);
@@ -3764,12 +3764,12 @@ void destroy_tcp()
                        shm_free(tcp_connections_no);
                        tcp_connections_no=0;
                }
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
                if (tcp_total_wq){
                        shm_free(tcp_total_wq);
                        tcp_total_wq=0;
                }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
                if (connection_id){
                        shm_free(connection_id);
                        connection_id=0;
@@ -3826,13 +3826,13 @@ int init_tcp()
                goto error;
        }
        *connection_id=1;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        tcp_total_wq=shm_malloc(sizeof(*tcp_total_wq));
        if (tcp_total_wq==0){
                LOG(L_CRIT, "ERROR: init_tcp: could not alloc globals\n");
                goto error;
        }
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        /* alloc hashtables*/
        tcpconn_aliases_hash=(struct tcp_conn_alias**)
                        shm_malloc(TCP_ALIAS_HASH_SIZE* sizeof(struct tcp_conn_alias*));
@@ -3981,11 +3981,11 @@ void tcp_get_info(struct tcp_gen_info *ti)
        ti->tcp_readers=tcp_children_no;
        ti->tcp_max_connections=tcp_max_connections;
        ti->tcp_connections_no=*tcp_connections_no;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        ti->tcp_write_queued=*tcp_total_wq;
 #else
        ti->tcp_write_queued=0;
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 }
 
 #endif
index a292b01..f66a7ae 100644 (file)
@@ -41,7 +41,7 @@ struct cfg_group_tcp tcp_default_cfg;
 {
        1, /* fd_cache, default on */
        /* tcp async options */
-       0, /* tcp_buf_write / tcp_async, default off */
+       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)*/
@@ -147,15 +147,15 @@ void init_tcp_options()
        tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
        tcp_default_cfg.con_lifetime_s=DEFAULT_TCP_CONNECTION_LIFETIME_S;
        tcp_default_cfg.max_connections=tcp_max_connections;
-#ifdef TCP_BUF_WRITE
-       tcp_default_cfg.tcp_buf_write=0;
+#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 */
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 #ifdef TCP_FD_CACHE
        tcp_default_cfg.fd_cache=1;
 #endif
@@ -229,9 +229,9 @@ static int fix_send_to(void* cfg_h, str* name, void** val)
        fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
                                                TICKS_TO_S(MAX_TCP_CON_LIFETIME));
        *val=(void*)(long)v;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        ((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        return 0;
 }
 
@@ -244,9 +244,9 @@ static int fix_con_lt(void* cfg_h, str* name, void** val)
                                                TICKS_TO_S(MAX_TCP_CON_LIFETIME),
                                                TICKS_TO_S(MAX_TCP_CON_LIFETIME));
        *val=(void*)(long)v;
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        ((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        return 0;
 }
 
@@ -273,19 +273,17 @@ void tcp_options_check()
        W_OPT_NC(defer_accept);
 #endif
 
-#ifndef TCP_BUF_WRITE
-       W_OPT_NC(tcp_buf_write);
+#ifndef TCP_ASYNC
+       W_OPT_NC(async);
        W_OPT_NC(tcpconn_wq_max);
        W_OPT_NC(tcp_wq_max);
        W_OPT_NC(tcp_wq_timeout);
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
 #ifndef TCP_CONNECT_WAIT
        W_OPT_NC(tcp_connect_wait);
 #endif /* TCP_CONNECT_WAIT */
        
-       if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.tcp_buf_write){
-               WARN("tcp_options: tcp_connect_wait depends on tcp_buf_write, "
-                               " disabling...\n");
+       if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.async){
                tcp_default_cfg.tcp_connect_wait=0;
        }
        
@@ -328,9 +326,9 @@ void tcp_options_check()
                                                TICKS_TO_S(MAX_TCP_CON_LIFETIME),
                                                TICKS_TO_S(MAX_TCP_CON_LIFETIME));
        /* compute timeout in ticks */
-#ifdef TCP_BUF_WRITE
+#ifdef TCP_ASYNC
        tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
-#endif /* TCP_BUF_WRITE */
+#endif /* TCP_ASYNC */
        tcp_default_cfg.con_lifetime=S_TO_TICKS(tcp_default_cfg.con_lifetime_s);
        tcp_default_cfg.max_connections=tcp_max_connections;
 }
index cf90f17..7a05e59 100644 (file)
 
 #ifdef USE_TCP
 
-#ifndef NO_TCP_BUF_WRITE
-#define TCP_BUF_WRITE /* enabled buffered writing */
-#endif 
+#ifndef NO_TCP_ASYNC
+#define TCP_ASYNC /* enabled async mode */
+#endif
 
-#if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_BUF_WRITE)
+#if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
 #define TCP_CONNECT_WAIT /* enable pending connects support */
 #endif
 
-#if defined(TCP_CONNECT_WAIT) && !defined(TCP_BUF_WRITE)
-/* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_BUF_WRITE */
-#warning "disabling TCP_CONNECT_WAIT because TCP_BUF_WRITE is not defined"
+#if defined(TCP_CONNECT_WAIT) && !defined(TCP_ASYNC)
+/* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_ASYNC */
+#warning "disabling TCP_CONNECT_WAIT because TCP_ASYNC is not defined"
 #undef TCP_CONNECT_WAIT
 #endif
 
@@ -117,8 +117,8 @@ struct cfg_group_tcp{
        int max_connections;
        int fd_cache; /* on /off */
        /* tcp async options */
-       int tcp_buf_write; /* on / off */
-       int tcp_connect_wait; /* on / off, depends on tcp_buf_write */
+       int async; /* on / off */
+       int tcp_connect_wait; /* on / off, depends on async */
        unsigned int tcpconn_wq_max; /* maximum queue len per connection */
        unsigned int tcp_wq_max; /* maximum overall queued bytes */