Skip to content

Commit

Permalink
core: execute event_route[core:worker-one-init] for sctp or tcp
Browse files Browse the repository at this point in the history
- if no udp worker is started, the event route is executed by next
available transport, in the order: sctp, tcp (or tls)
  • Loading branch information
miconda committed Mar 12, 2021
1 parent 087c00a commit dc6d44b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/core/tcp_init.h
Expand Up @@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

Expand Down Expand Up @@ -54,7 +54,7 @@ struct tcp_child{
int init_tcp(void);
void destroy_tcp(void);
int tcp_init(struct socket_info* sock_info);
int tcp_init_children(void);
int tcp_init_children(int *woneinit);
void tcp_main_loop(void);
void tcp_receive_loop(int unix_sock);
int tcp_fix_child_sockets(int* fd);
Expand Down
18 changes: 12 additions & 6 deletions src/core/tcp_main.c
Expand Up @@ -5034,29 +5034,29 @@ int tcp_fix_child_sockets(int* fd)


/* starts the tcp processes */
int tcp_init_children()
int tcp_init_children(int *woneinit)
{
int r, i;
int reader_fd_1; /* for comm. with the tcp children read */
pid_t pid;
char si_desc[MAX_PT_DESC];
struct socket_info *si;

/* estimate max fd. no:
* 1 tcp send unix socket/all_proc,
* 1 tcp send unix socket/all_proc,
* + 1 udp sock/udp proc + 1 tcp_child sock/tcp child*
* + no_listen_tcp */
for(r=0, si=tcp_listen; si; si=si->next, r++);
#ifdef USE_TLS
if (! tls_disable)
for (si=tls_listen; si; si=si->next, r++);
#endif

register_fds(r+tcp_max_connections+get_max_procs()-1 /* tcp main */);
#if 0
tcp_max_fd_no=get_max_procs()*2 +r-1 /* timer */ +3; /* stdin/out/err*/
/* max connections can be temporarily exceeded with estimated_process_count
* - tcp_main (tcpconn_connect called simultaneously in all all the
* - tcp_main (tcpconn_connect called simultaneously in all all the
* processes) */
tcp_max_fd_no+=tcp_max_connections+get_max_procs()-1 /* tcp main */;
#endif
Expand Down Expand Up @@ -5095,7 +5095,7 @@ int tcp_init_children()

/* create the tcp sock_info structures */
/* copy the sockets --moved to main_loop*/

/* fork children & create the socket pairs*/
for(r=0; r<tcp_children_no; r++){
child_rank++;
Expand All @@ -5108,10 +5108,16 @@ int tcp_init_children()
goto error;
}else if (pid>0){
/* parent */
*woneinit = 1;
}else{
/* child */
bind_address=0; /* force a SEGFAULT if someone uses a non-init.
bind address on tcp */
if(*woneinit==0) {
if(run_child_one_init_route()<0)
goto error;
}

tcp_receive_loop(reader_fd_1);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main.c
Expand Up @@ -1720,8 +1720,14 @@ int main_loop(void)
/* child */
bind_address=si; /* shortcut */

if(woneinit==0) {
if(run_child_one_init_route()<0)
goto error;
}

return sctp_core_rcv_loop();
}
woneinit = 1;
}
/*parent*/
/*close(sctp_sock)*/; /*if closed=>sendto invalid fd errors?*/
Expand Down Expand Up @@ -1777,7 +1783,7 @@ int main_loop(void)
#ifdef USE_TCP
if (!tcp_disable){
/* start tcp & tls receivers */
if (tcp_init_children()<0) goto error;
if (tcp_init_children(&woneinit)<0) goto error;
/* start tcp+tls main attendant proc */
pid = fork_process(PROC_TCP_MAIN, "tcp main process", 0);
if (pid<0){
Expand Down

0 comments on commit dc6d44b

Please sign in to comment.