Skip to content

Commit 2533ae6

Browse files
committed
Merge pull request #3664 from 36952362/tcp_connection
Resolve the issue of inaccurate tcp_connections_no (cherry picked from commit 38efd08)
1 parent bfa7ef4 commit 2533ae6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

net/net_tcp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static inline void tcpconn_ref(struct tcp_connection* c)
889889

890890
static struct tcp_connection* tcpconn_new(int sock, const union sockaddr_union* su,
891891
const struct socket_info* si, const struct tcp_conn_profile *prof,
892-
int state, int flags)
892+
int state, int flags, int in_main_proc)
893893
{
894894
struct tcp_connection *c;
895895
union sockaddr_union local_su;
@@ -956,8 +956,8 @@ static struct tcp_connection* tcpconn_new(int sock, const union sockaddr_union*
956956
goto error;
957957
}
958958
}
959-
960-
tcp_connections_no++;
959+
if(in_main_proc)
960+
tcp_connections_no++;
961961
return c;
962962

963963
error:
@@ -984,7 +984,7 @@ struct tcp_connection* tcp_conn_create(int sock, const union sockaddr_union* su,
984984
tcp_con_get_profile(su, &si->su, si->proto, prof);
985985

986986
/* create the connection structure */
987-
c = tcpconn_new(sock, su, si, prof, state, 0);
987+
c = tcpconn_new(sock, su, si, prof, state, 0, !send2main);
988988
if (c==NULL) {
989989
LM_ERR("tcpconn_new failed\n");
990990
return NULL;
@@ -1127,7 +1127,7 @@ static inline int handle_new_connect(const struct socket_info* si)
11271127
}
11281128

11291129
/* add socket to list */
1130-
tcpconn=tcpconn_new(new_sock, &su, si, &prof, S_CONN_OK, F_CONN_ACCEPTED);
1130+
tcpconn=tcpconn_new(new_sock, &su, si, &prof, S_CONN_OK, F_CONN_ACCEPTED, 1);
11311131
if (tcpconn){
11321132
tcpconn->refcnt++; /* safe, not yet available to the
11331133
outside world */
@@ -1506,6 +1506,7 @@ inline static int handle_worker(struct process_table* p, int fd_i)
15061506
tcpconn->s=fd;
15071507
/* add tcpconn to the list*/
15081508
tcpconn_add(tcpconn);
1509+
tcp_connections_no++;
15091510
reactor_add_reader( tcpconn->s, F_TCPCONN, RCT_PRIO_NET, tcpconn);
15101511
tcpconn->flags&=~F_CONN_REMOVED_READ;
15111512
break;
@@ -1519,6 +1520,7 @@ inline static int handle_worker(struct process_table* p, int fd_i)
15191520
tcpconn->s=fd;
15201521
/* add tcpconn to the list*/
15211522
tcpconn_add(tcpconn);
1523+
tcp_connections_no++;
15221524
/* FIXME - now we have lifetime==default_lifetime - should we
15231525
* set a shorter one when waiting for a connect ??? */
15241526
/* only maintain the socket in the IO_WATCH_WRITE watcher

0 commit comments

Comments
 (0)