diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-12 20:27:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-12 20:27:56 +0000 |
commit | f3703bf34939a40c95607df3b1cb2924e3e86079 (patch) | |
tree | c4a09d7372636b306a4a6e79d1d92b9037ac40fa /nuttx/netutils/thttpd/thttpd.c | |
parent | ad855c503fab41c8943a94c5c4dfafc25019491b (diff) | |
download | px4-nuttx-f3703bf34939a40c95607df3b1cb2924e3e86079.tar.gz px4-nuttx-f3703bf34939a40c95607df3b1cb2924e3e86079.tar.bz2 px4-nuttx-f3703bf34939a40c95607df3b1cb2924e3e86079.zip |
Add fdwatch.c and timers.c
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1981 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils/thttpd/thttpd.c')
-rw-r--r-- | nuttx/netutils/thttpd/thttpd.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/nuttx/netutils/thttpd/thttpd.c b/nuttx/netutils/thttpd/thttpd.c index 105cfb889..cccacaf3b 100644 --- a/nuttx/netutils/thttpd/thttpd.c +++ b/nuttx/netutils/thttpd/thttpd.c @@ -79,6 +79,9 @@ #define CNST_PAUSING 3 #define CNST_LINGERING 4 +#define SPARE_FDS 2 +#define AVAILABLE_FDS (CONFIG_NSOCKET_DESCRIPTORS - SPARE_FDS) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -103,7 +106,6 @@ struct connect_s static httpd_server *hs = NULL; static struct connect_s *connects; static int num_connects; -static int max_connects; static int first_free_connect; static int httpd_conn_count; @@ -156,7 +158,7 @@ static void shut_down(void) (void)gettimeofday(&tv, (struct timezone *)0); logstats(&tv); - for (cnum = 0; cnum < max_connects; ++cnum) + for (cnum = 0; cnum < AVAILABLE_FDS; ++cnum) { if (connects[cnum].conn_state != CNST_FREE) { @@ -199,7 +201,7 @@ static int handle_newconnect(struct timeval *tv, int listen_fd) for (;;) { /* Is there room in the connection table? */ - if (num_connects >= max_connects) + if (num_connects >= AVAILABLE_FDS) { /* Out of connection slots. Run the timers, then the existing * connections, and maybe we'll free up a slot by the time we get @@ -613,7 +615,7 @@ static void idle(ClientData client_data, struct timeval *nowP) int cnum; struct connect_s *conn; - for (cnum = 0; cnum < max_connects; ++cnum) + for (cnum = 0; cnum < AVAILABLE_FDS; ++cnum) { conn = &connects[cnum]; switch (conn->conn_state) @@ -740,6 +742,7 @@ int thttpd_main(int argc, char **argv) struct sockaddr_in sa; #endif struct timeval tv; + int ret; /* Setup host address */ @@ -754,7 +757,8 @@ int thttpd_main(int argc, char **argv) /* Switch directories if requested */ #ifdef CONFIG_THTTPD_DIR - if (chdir(CONFIG_THTTPD_DIR) < 0) + ret = chdir(CONFIG_THTTPD_DIR); + if (ret < 0) { ndbg("chdir: %d\n", errno); exit(1); @@ -771,8 +775,8 @@ int thttpd_main(int argc, char **argv) /* Initialize the fdwatch package */ - max_connects = fdwatch_get_nfiles(); - if (max_connects < 0) + ret = fdwatch_initialize(); + if (ret < 0) { ndbg("fdwatch initialization failure\n"); exit(1); @@ -834,21 +838,21 @@ int thttpd_main(int argc, char **argv) /* Initialize our connections table */ - connects = NEW(struct connect_s, max_connects); + connects = NEW(struct connect_s, AVAILABLE_FDS); if (connects == (struct connect_s *) 0) { ndbg("out of memory allocating a struct connect_s\n"); exit(1); } - for (cnum = 0; cnum < max_connects; ++cnum) + for (cnum = 0; cnum < AVAILABLE_FDS; ++cnum) { connects[cnum].conn_state = CNST_FREE; connects[cnum].next_free_connect = cnum + 1; connects[cnum].hc = (httpd_conn *) 0; } - connects[max_connects - 1].next_free_connect = -1; /* end of link list */ + connects[AVAILABLE_FDS - 1].next_free_connect = -1; /* end of link list */ first_free_connect = 0; num_connects = 0; httpd_conn_count = 0; |