diff options
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/net/net_close.c | 2 | ||||
-rw-r--r-- | nuttx/net/netdev_findbyaddr.c | 2 | ||||
-rw-r--r-- | nuttx/net/netdev_txnotify.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip_listen.c | 4 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpconn.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpinput.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcppoll.c | 4 | ||||
-rw-r--r-- | nuttx/netutils/thttpd/fdwatch.c | 5 | ||||
-rw-r--r-- | nuttx/netutils/thttpd/thttpd.c | 12 | ||||
-rw-r--r-- | nuttx/netutils/thttpd/timers.c | 258 |
10 files changed, 158 insertions, 135 deletions
diff --git a/nuttx/net/net_close.c b/nuttx/net/net_close.c index 7432d2482..eb7dbd711 100644 --- a/nuttx/net/net_close.c +++ b/nuttx/net/net_close.c @@ -297,7 +297,7 @@ int net_close(int sockfd) return OK; errout: - *get_errno_ptr() = err; + errno = err; return ERROR; } diff --git a/nuttx/net/netdev_findbyaddr.c b/nuttx/net/netdev_findbyaddr.c index 1b326b3ba..14bd27709 100644 --- a/nuttx/net/netdev_findbyaddr.c +++ b/nuttx/net/netdev_findbyaddr.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/netdev_findbyaddr.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/net/netdev_txnotify.c b/nuttx/net/netdev_txnotify.c index 0fd03b0c3..fb6f12893 100644 --- a/nuttx/net/netdev_txnotify.c +++ b/nuttx/net/netdev_txnotify.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/netdev_txnotify.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/net/uip/uip_listen.c b/nuttx/net/uip/uip_listen.c index f93501927..f4dfdf6ff 100644 --- a/nuttx/net/uip/uip_listen.c +++ b/nuttx/net/uip/uip_listen.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_listen.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * A direct leverage of logic from uIP which also has b BSD style license @@ -256,7 +256,7 @@ int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, uint16 portno) * may be waiting on poll()/select() that the connection is available. */ - ret = uip_backlogadd(listener, conn); + ret = uip_backlogadd(listener, conn); if (ret == OK) { (void)uip_tcpcallback(dev, listener, UIP_BACKLOG); diff --git a/nuttx/net/uip/uip_tcpconn.c b/nuttx/net/uip/uip_tcpconn.c index 12451a47f..a6f28d3c6 100644 --- a/nuttx/net/uip/uip_tcpconn.c +++ b/nuttx/net/uip/uip_tcpconn.c @@ -347,7 +347,7 @@ void uip_tcpfree(struct uip_conn *conn) * * Description: * Find a connection structure that is the appropriate - * connection to be used withi the provided TCP/IP header + * connection to be used with the provided TCP/IP header * * Assumptions: * This function is called from UIP logic at interrupt level diff --git a/nuttx/net/uip/uip_tcpinput.c b/nuttx/net/uip/uip_tcpinput.c index 362229d74..3fc491f6b 100644 --- a/nuttx/net/uip/uip_tcpinput.c +++ b/nuttx/net/uip/uip_tcpinput.c @@ -161,7 +161,7 @@ void uip_tcpinput(struct uip_driver_s *dev) conn = uip_tcpaccept(pbuf); if (conn) { - /* The connection structure was successfully allocated. Now see + /* The connection structure was successfully allocated. Now see if * there is an application waiting to accept the connection (or at * least queue it it for acceptance). */ diff --git a/nuttx/net/uip/uip_tcppoll.c b/nuttx/net/uip/uip_tcppoll.c index 66a49f953..b851ba167 100644 --- a/nuttx/net/uip/uip_tcppoll.c +++ b/nuttx/net/uip/uip_tcppoll.c @@ -2,7 +2,7 @@ * net/uip/uip_tcppoll.c * Poll for the availability of TCP TX data * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Adapted for NuttX from logic in uIP which also has a BSD-like license: @@ -97,7 +97,7 @@ void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn) uint8 result; /* Verify that the connection is established and if the connection has - * oustanding (unacknowledged) sent data. + * no outstanding (unacknowledged) sent data. */ if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && diff --git a/nuttx/netutils/thttpd/fdwatch.c b/nuttx/netutils/thttpd/fdwatch.c index 2346d7450..77e1318c3 100644 --- a/nuttx/netutils/thttpd/fdwatch.c +++ b/nuttx/netutils/thttpd/fdwatch.c @@ -285,10 +285,13 @@ int fdwatch(struct fdwatch_s *fw, long timeout_msecs) { /* Is there activity on this descriptor? */ - if (fw->pollfds[i].revents & (POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL)) + if (fw->pollfds[i].revents & (POLLIN | POLLERR | POLLHUP | POLLNVAL)) { /* Yes... save it in a shorter list */ + nvdbg("pollndx: %d fd: %d revents: %04x\n", + i, fw->pollfds[i].fd, fw->pollfds[i].revents); + fw->ready[fw->nactive++] = fw->pollfds[i].fd; if (fw->nactive == ret) { diff --git a/nuttx/netutils/thttpd/thttpd.c b/nuttx/netutils/thttpd/thttpd.c index 224ccd1af..b1e90b6c7 100644 --- a/nuttx/netutils/thttpd/thttpd.c +++ b/nuttx/netutils/thttpd/thttpd.c @@ -565,8 +565,7 @@ static void clear_connection(struct connect_s *conn, struct timeval *tv) conn->linger_timer = NULL; conn->hc->should_linger = FALSE; } - - if (conn->hc->should_linger) + else if (conn->hc->should_linger) { fdwatch_del_fd(fw, conn->hc->conn_fd); conn->conn_state = CNST_LINGERING; @@ -893,14 +892,7 @@ int thttpd_main(int argc, char **argv) if (conn) { hc = conn->hc; - if (!fdwatch_check_fd(fw, hc->conn_fd)) - { - /* Something went wrong */ - - nvdbg("Clearing connection\n"); - clear_connection(conn, &tv); - } - else + if (fdwatch_check_fd(fw, hc->conn_fd)) { nvdbg("Handle conn_state %d\n", conn->conn_state); switch (conn->conn_state) diff --git a/nuttx/netutils/thttpd/timers.c b/nuttx/netutils/thttpd/timers.c index e67adb37a..6b56c6b2a 100644 --- a/nuttx/netutils/thttpd/timers.c +++ b/nuttx/netutils/thttpd/timers.c @@ -60,7 +60,11 @@ static Timer *timers[HASH_SIZE]; static Timer *free_timers; -static int alloc_count, active_count, free_count; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) +static int alloc_count; +static int active_count; +static int free_count; +#endif /**************************************************************************** * Public Data @@ -72,7 +76,7 @@ ClientData JunkClientData; * Private Functions ****************************************************************************/ -static unsigned int hash(Timer *t) +static unsigned int hash(Timer *tmr) { /* We can hash on the trigger time, even though it can change over the * life of a timer via the periodic bit. @@ -80,97 +84,97 @@ static unsigned int hash(Timer *t) * the hash and moves the timer to the appropriate list. */ - return ((unsigned int)t->time.tv_sec ^ - (unsigned int)t->time.tv_usec) % HASH_SIZE; + return ((unsigned int)tmr->time.tv_sec ^ + (unsigned int)tmr->time.tv_usec) % HASH_SIZE; } -static void l_add(Timer * t) +static void l_add(Timer *tmr) { - int h = t->hash; - register Timer *t2; - register Timer *t2prev; + int h = tmr->hash; + register Timer *tmr2; + register Timer *tmr2prev; - t2 = timers[h]; - if (t2 == NULL) + tmr2 = timers[h]; + if (tmr2 == NULL) { /* The list is empty. */ - timers[h] = t; - t->prev = t->next = NULL; + timers[h] = tmr; + tmr->prev = tmr->next = NULL; } else { - if (t->time.tv_sec < t2->time.tv_sec || - (t->time.tv_sec == t2->time.tv_sec && - t->time.tv_usec <= t2->time.tv_usec)) + if (tmr->time.tv_sec < tmr2->time.tv_sec || + (tmr->time.tv_sec == tmr2->time.tv_sec && + tmr->time.tv_usec <= tmr2->time.tv_usec)) { /* The new timer goes at the head of the list. */ - timers[h] = t; - t->prev = NULL; - t->next = t2; - t2->prev = t; + timers[h] = tmr; + tmr->prev = NULL; + tmr->next = tmr2; + tmr2->prev = tmr; } else { /* Walk the list to find the insertion point. */ - for (t2prev = t2, t2 = t2->next; t2 != NULL; - t2prev = t2, t2 = t2->next) + for (tmr2prev = tmr2, tmr2 = tmr2->next; tmr2 != NULL; + tmr2prev = tmr2, tmr2 = tmr2->next) { - if (t->time.tv_sec < t2->time.tv_sec || - (t->time.tv_sec == t2->time.tv_sec && - t->time.tv_usec <= t2->time.tv_usec)) + if (tmr->time.tv_sec < tmr2->time.tv_sec || + (tmr->time.tv_sec == tmr2->time.tv_sec && + tmr->time.tv_usec <= tmr2->time.tv_usec)) { /* Found it. */ - t2prev->next = t; - t->prev = t2prev; - t->next = t2; - t2->prev = t; + tmr2prev->next = tmr; + tmr->prev = tmr2prev; + tmr->next = tmr2; + tmr2->prev = tmr; return; } } /* Oops, got to the end of the list. Add to tail. */ - t2prev->next = t; - t->prev = t2prev; - t->next = NULL; + tmr2prev->next = tmr; + tmr->prev = tmr2prev; + tmr->next = NULL; } } } -static void l_remove(Timer * t) +static void l_remove(Timer *tmr) { - int h = t->hash; + int h = tmr->hash; - if (t->prev == NULL) + if (tmr->prev == NULL) { - timers[h] = t->next; + timers[h] = tmr->next; } else { - t->prev->next = t->next; + tmr->prev->next = tmr->next; } - if (t->next != NULL) + if (tmr->next != NULL) { - t->next->prev = t->prev; + tmr->next->prev = tmr->prev; } } -static void l_resort(Timer * t) +static void l_resort(Timer *tmr) { /* Remove the timer from its old list. */ - l_remove(t); + l_remove(tmr); /* Recompute the hash. */ - t->hash = hash(t); + tmr->hash = hash(tmr); /* And add it back in to its new list, sorted correctly. */ - l_add(t); + l_add(tmr); } /**************************************************************************** @@ -187,66 +191,78 @@ void tmr_init(void) } free_timers = NULL; - alloc_count = active_count = free_count = 0; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) + alloc_count = 0; + active_count = 0; + free_count = 0; +#endif } -Timer *tmr_create(struct timeval *nowP, TimerProc * timer_proc, +Timer *tmr_create(struct timeval *now, TimerProc *timer_proc, ClientData client_data, long msecs, int periodic) { - Timer *t; + Timer *tmr; if (free_timers != NULL) { - t = free_timers; - free_timers = t->next; + tmr = free_timers; + free_timers = tmr->next; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) --free_count; +#endif } else { - t = (Timer*)httpd_malloc(sizeof(Timer)); - if (!t) + tmr = (Timer*)httpd_malloc(sizeof(Timer)); + if (!tmr) { return NULL; } +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) alloc_count++; +#endif } - t->timer_proc = timer_proc; - t->client_data = client_data; - t->msecs = msecs; - t->periodic = periodic; + tmr->timer_proc = timer_proc; + tmr->client_data = client_data; + tmr->msecs = msecs; + tmr->periodic = periodic; - if (nowP != NULL) + if (now != NULL) { - t->time = *nowP; + tmr->time = *now; } else { - (void)gettimeofday(&t->time, NULL); + (void)gettimeofday(&tmr->time, NULL); } - t->time.tv_sec += msecs / 1000L; - t->time.tv_usec += (msecs % 1000L) * 1000L; - if (t->time.tv_usec >= 1000000L) + tmr->time.tv_sec += msecs / 1000L; + tmr->time.tv_usec += (msecs % 1000L) * 1000L; + if (tmr->time.tv_usec >= 1000000L) { - t->time.tv_sec += t->time.tv_usec / 1000000L; - t->time.tv_usec %= 1000000L; + tmr->time.tv_sec += tmr->time.tv_usec / 1000000L; + tmr->time.tv_usec %= 1000000L; } - t->hash = hash(t); + tmr->hash = hash(tmr); /* Add the new timer to the proper active list. */ - l_add(t); - ++active_count; - return t; + l_add(tmr); +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) + active_count++; +#endif + + nvdbg("Return: %p\n", tmr); + return tmr; } -long tmr_mstimeout(struct timeval *nowP) +long tmr_mstimeout(struct timeval *now) { int h; int gotone; long msecs, m; - register Timer *t; + register Timer *tmr; gotone = 0; msecs = 0; @@ -257,11 +273,11 @@ long tmr_mstimeout(struct timeval *nowP) for (h = 0; h < HASH_SIZE; ++h) { - t = timers[h]; - if (t != NULL) + tmr = timers[h]; + if (tmr != NULL) { - m = (t->time.tv_sec - nowP->tv_sec) * 1000L + - (t->time.tv_usec - nowP->tv_usec) / 1000L; + m = (tmr->time.tv_sec - now->tv_sec) * 1000L + + (tmr->time.tv_usec - now->tv_usec) / 1000L; if (!gotone) { msecs = m; @@ -287,74 +303,86 @@ long tmr_mstimeout(struct timeval *nowP) return msecs; } -void tmr_run(struct timeval *nowP) +void tmr_run(struct timeval *now) { int h; - Timer *t; + Timer *tmr; Timer *next; for (h = 0; h < HASH_SIZE; ++h) - for (t = timers[h]; t != NULL; t = next) - { - next = t->next; - - /* Since the lists are sorted, as soon as we find a timer * that isn't - * ready yet, we can go on to the next list - */ - - if (t->time.tv_sec > nowP->tv_sec || - (t->time.tv_sec == nowP->tv_sec && t->time.tv_usec > nowP->tv_usec)) - { - break; - } - - (t->timer_proc)(t->client_data, nowP); - if (t->periodic) - { - /* Reschedule. */ - - t->time.tv_sec += t->msecs / 1000L; - t->time.tv_usec += (t->msecs % 1000L) * 1000L; - if (t->time.tv_usec >= 1000000L) - { - t->time.tv_sec += t->time.tv_usec / 1000000L; - t->time.tv_usec %= 1000000L; - } - l_resort(t); - } - else - { - tmr_cancel(t); - } - } + { + for (tmr = timers[h]; tmr != NULL; tmr = next) + { + next = tmr->next; + + /* Since the lists are sorted, as soon as we find a timer * that isn'tmr + * ready yet, we can go on to the next list + */ + + if (tmr->time.tv_sec > now->tv_sec || + (tmr->time.tv_sec == now->tv_sec && tmr->time.tv_usec > now->tv_usec)) + { + break; + } + + (tmr->timer_proc)(tmr->client_data, now); + if (tmr->periodic) + { + /* Reschedule. */ + + tmr->time.tv_sec += tmr->msecs / 1000L; + tmr->time.tv_usec += (tmr->msecs % 1000L) * 1000L; + if (tmr->time.tv_usec >= 1000000L) + { + tmr->time.tv_sec += tmr->time.tv_usec / 1000000L; + tmr->time.tv_usec %= 1000000L; + } + l_resort(tmr); + } + else + { + tmr_cancel(tmr); + } + } + } } -void tmr_cancel(Timer * t) +void tmr_cancel(Timer *tmr) { + nvdbg("tmr: %p\n", tmr); + /* Remove it from its active list. */ - l_remove(t); + l_remove(tmr); +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) active_count--; +#endif /* And put it on the free list. */ - t->next = free_timers; - free_timers = t; + tmr->next = free_timers; + free_timers = tmr; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) free_count++; - t->prev = NULL; +#endif + tmr->prev = NULL; } void tmr_cleanup(void) { - Timer *t; + Timer *tmr; while (free_timers != NULL) { - t = free_timers; - free_timers = t->next; + tmr = free_timers; + free_timers = tmr->next; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) free_count--; - httpd_free((void*)t); +#endif + httpd_free((void*)tmr); +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET) alloc_count--; +#endif } } |