Ver Fonte

- added register_fds(no), used to register the maximum numbers of fds opened by a module (on a per process basis). Needed for code that needs to know the maximum possible open fd number (like the tcp code).
- added get_max_open_fds()

Andrei Pelinescu-Onciul há 18 anos atrás
pai
commit
3e99928136
4 ficheiros alterados com 9 adições e 7 exclusões
  1. 0 1
      globals.h
  2. 1 0
      main.c
  3. 7 5
      tcp_main.c
  4. 1 1
      tcp_read.c

+ 0 - 1
globals.h

@@ -84,7 +84,6 @@ extern int tcp_connect_timeout;
 extern int tcp_send_timeout;
 extern int tcp_con_lifetime; /* connection lifetime */
 extern enum poll_types tcp_poll_method;
-extern int tcp_max_fd_no;
 extern int tcp_max_connections;
 extern int tcp_use_source_ipv4;
 extern struct sockaddr_in tcp_source_ipv4;

+ 1 - 0
main.c

@@ -1157,6 +1157,7 @@ int main_loop()
 		fprintf(stderr, "% 3d   % 5d - %s\n", r, pt[r].pid, pt[r].desc);
 	}
 #endif
+	DBG("Expect maximum %d  open fds\n", get_max_open_fds());
 
 	for(;;){
 			handle_sigs();

+ 7 - 5
tcp_main.c

@@ -148,7 +148,7 @@
 #ifndef TCP_CHILD_NON_BLOCKING
 #define TCP_CHILD_NON_BLOCKING
 #endif
-#define MAX_SEND_FD_QUEUE_SIZE	tcp_max_fd_no
+#define MAX_SEND_FD_QUEUE_SIZE	tcp_main_max_fd_no
 #define SEND_FD_QUEUE_SIZE		128  /* initial size */
 #define MAX_SEND_FD_RETRIES		96	 /* FIXME: not used for now */
 #define SEND_FD_QUEUE_TIMEOUT	MS_TO_TICKS(2000)  /* 2 s */
@@ -170,7 +170,7 @@ int tcp_send_timeout=DEFAULT_TCP_SEND_TIMEOUT;
 int tcp_con_lifetime=DEFAULT_TCP_CONNECTION_LIFETIME;
 enum poll_types tcp_poll_method=0; /* by default choose the best method */
 int tcp_max_connections=DEFAULT_TCP_MAX_CONNECTIONS;
-int tcp_max_fd_no=0;
+int tcp_main_max_fd_no=0;
 
 int tcp_use_source_ipv4 = 0;
 struct sockaddr_in tcp_source_ipv4;
@@ -1691,6 +1691,7 @@ void tcp_main_loop()
 	
 	is_tcp_main=1; /* mark this process as tcp main */
 	
+	tcp_main_max_fd_no=get_max_open_fds();
 	/* init send fd queues (here because we want mem. alloc only in the tcp
 	 *  process */
 #ifdef SEND_FD_QUEUE
@@ -1701,8 +1702,7 @@ void tcp_main_loop()
 #endif
 	/* init io_wait (here because we want the memory allocated only in
 	 * the tcp_main process) */
-	
-	if  (init_io_wait(&io_h, tcp_max_fd_no, tcp_poll_method)<0)
+	if  (init_io_wait(&io_h, tcp_main_max_fd_no, tcp_poll_method)<0)
 		goto error;
 	/* init: start watching all the fds*/
 	
@@ -2023,12 +2023,14 @@ int tcp_init_children()
 		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 
 	 *  processes) */
 	tcp_max_fd_no+=tcp_max_connections+get_max_procs()-1 /* tcp main */;
-	
+#endif
 	/* alloc the children array */
 	tcp_children=pkg_malloc(sizeof(struct tcp_child)*tcp_children_no);
 	if (tcp_children==0){

+ 1 - 1
tcp_read.c

@@ -963,7 +963,7 @@ void tcp_receive_loop(int unix_sock)
 	
 	/* init */
 	tcpmain_sock=unix_sock; /* init com. socket */
-	if (init_io_wait(&io_w, tcp_max_fd_no, tcp_poll_method)<0)
+	if (init_io_wait(&io_w, get_max_open_fds(), tcp_poll_method)<0)
 		goto error;
 	/* add the unix socket */
 	if (io_watch_add(&io_w, tcpmain_sock, F_TCPMAIN, 0)<0){