Browse code

- 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 authored on 04/07/2007 17:27:33
Showing 4 changed files
... ...
@@ -84,7 +84,6 @@ extern int tcp_connect_timeout;
84 84
 extern int tcp_send_timeout;
85 85
 extern int tcp_con_lifetime; /* connection lifetime */
86 86
 extern enum poll_types tcp_poll_method;
87
-extern int tcp_max_fd_no;
88 87
 extern int tcp_max_connections;
89 88
 extern int tcp_use_source_ipv4;
90 89
 extern struct sockaddr_in tcp_source_ipv4;
... ...
@@ -1157,6 +1157,7 @@ int main_loop()
1157 1157
 		fprintf(stderr, "% 3d   % 5d - %s\n", r, pt[r].pid, pt[r].desc);
1158 1158
 	}
1159 1159
 #endif
1160
+	DBG("Expect maximum %d  open fds\n", get_max_open_fds());
1160 1161
 
1161 1162
 	for(;;){
1162 1163
 			handle_sigs();
... ...
@@ -148,7 +148,7 @@
148 148
 #ifndef TCP_CHILD_NON_BLOCKING
149 149
 #define TCP_CHILD_NON_BLOCKING
150 150
 #endif
151
-#define MAX_SEND_FD_QUEUE_SIZE	tcp_max_fd_no
151
+#define MAX_SEND_FD_QUEUE_SIZE	tcp_main_max_fd_no
152 152
 #define SEND_FD_QUEUE_SIZE		128  /* initial size */
153 153
 #define MAX_SEND_FD_RETRIES		96	 /* FIXME: not used for now */
154 154
 #define SEND_FD_QUEUE_TIMEOUT	MS_TO_TICKS(2000)  /* 2 s */
... ...
@@ -170,7 +170,7 @@ int tcp_send_timeout=DEFAULT_TCP_SEND_TIMEOUT;
170 170
 int tcp_con_lifetime=DEFAULT_TCP_CONNECTION_LIFETIME;
171 171
 enum poll_types tcp_poll_method=0; /* by default choose the best method */
172 172
 int tcp_max_connections=DEFAULT_TCP_MAX_CONNECTIONS;
173
-int tcp_max_fd_no=0;
173
+int tcp_main_max_fd_no=0;
174 174
 
175 175
 int tcp_use_source_ipv4 = 0;
176 176
 struct sockaddr_in tcp_source_ipv4;
... ...
@@ -1691,6 +1691,7 @@ void tcp_main_loop()
1691 1691
 	
1692 1692
 	is_tcp_main=1; /* mark this process as tcp main */
1693 1693
 	
1694
+	tcp_main_max_fd_no=get_max_open_fds();
1694 1695
 	/* init send fd queues (here because we want mem. alloc only in the tcp
1695 1696
 	 *  process */
1696 1697
 #ifdef SEND_FD_QUEUE
... ...
@@ -1701,8 +1702,7 @@ void tcp_main_loop()
1701 1701
 #endif
1702 1702
 	/* init io_wait (here because we want the memory allocated only in
1703 1703
 	 * the tcp_main process) */
1704
-	
1705
-	if  (init_io_wait(&io_h, tcp_max_fd_no, tcp_poll_method)<0)
1704
+	if  (init_io_wait(&io_h, tcp_main_max_fd_no, tcp_poll_method)<0)
1706 1705
 		goto error;
1707 1706
 	/* init: start watching all the fds*/
1708 1707
 	
... ...
@@ -2023,12 +2023,14 @@ int tcp_init_children()
2023 2023
 		for (si=tls_listen; si; si=si->next, r++);
2024 2024
 #endif
2025 2025
 	
2026
+	register_fds(r+tcp_max_connections+get_max_procs()-1 /* tcp main */);
2027
+#if 0
2026 2028
 	tcp_max_fd_no=get_max_procs()*2 +r-1 /* timer */ +3; /* stdin/out/err*/
2027 2029
 	/* max connections can be temporarily exceeded with estimated_process_count
2028 2030
 	 * - tcp_main (tcpconn_connect called simultaneously in all all the 
2029 2031
 	 *  processes) */
2030 2032
 	tcp_max_fd_no+=tcp_max_connections+get_max_procs()-1 /* tcp main */;
2031
-	
2033
+#endif
2032 2034
 	/* alloc the children array */
2033 2035
 	tcp_children=pkg_malloc(sizeof(struct tcp_child)*tcp_children_no);
2034 2036
 	if (tcp_children==0){
... ...
@@ -963,7 +963,7 @@ void tcp_receive_loop(int unix_sock)
963 963
 	
964 964
 	/* init */
965 965
 	tcpmain_sock=unix_sock; /* init com. socket */
966
-	if (init_io_wait(&io_w, tcp_max_fd_no, tcp_poll_method)<0)
966
+	if (init_io_wait(&io_w, get_max_open_fds(), tcp_poll_method)<0)
967 967
 		goto error;
968 968
 	/* add the unix socket */
969 969
 	if (io_watch_add(&io_w, tcpmain_sock, F_TCPMAIN, 0)<0){