Fixed missing logic in readahead buffer logic

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@409 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2007-11-27 19:19:30 +00:00
parent c3a7c92677
commit 34e4d846a6
19 changed files with 82 additions and 136 deletions

View File

@ -253,3 +253,4 @@
* fs/ and lib/ subystem debug can not be selectively enabled/disabled
* Added vsnprintf
* Integrated uIP telnetd
* Add missing logic to readahead buffer logic

View File

@ -733,6 +733,7 @@ Other memory:
* fs/ and lib/ subystem debug can not be selectively enabled/disabled
* Added vsnprintf
* Integrated uIP telnetd
* Add missing logic to readahead buffer logic
</pre></ul>
<table width ="100%">

View File

@ -306,7 +306,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -306,7 +306,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -306,7 +306,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -306,7 +306,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -268,7 +268,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -269,7 +269,6 @@ CONFIG_EXAMPLE_UIP_SMTP=n
CONFIG_EXAMPLE_UIP_TELNETD=n
CONFIG_EXAMPLE_UIP_WEBSERVER=y
CONFIG_EXAMPLE_UIP_DHCPC=n
CONFIG_EXAMPLE_UIP_RESOLV=n
CONFIG_EXAMPLE_UIP_WEBCLIENT=n
#

View File

@ -59,21 +59,25 @@
* our project as defined in the config/<board-name>/defconfig file
*/
/* DHCPC may be used in conjunction with any other feature (or not) */
#if defined(CONFIG_EXAMPLE_UIP_DHCPC)
# include <net/uip/resolv.h>
# include <net/uip/dhcpc.h>
#endif
/* Pick the netutils feature under test (which may be DHCPC) */
#if defined(CONFIG_EXAMPLE_UIP_SMTP)
# include <net/uip/smtp.h>
#elif defined(CONFIG_EXAMPLE_UIP_TELNETD)
# include <net/uip/telnetd.h>
#elif defined(CONFIG_EXAMPLE_UIP_WEBSERVER)
# include <net/uip/httpd.h>
#elif defined(CONFIG_EXAMPLE_UIP_DHCPC)
# include <net/uip/resolv.h>
# include <net/uip/dhcpc.h>
#elif defined(CONFIG_EXAMPLE_UIP_RESOLV)
# include <net/uip/resolv.h>
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
# include <net/uip/resolv.h>
# include <net/uip/webclient.h>
#else
#elif !defined(CONFIG_EXAMPLE_UIP_DHCPC)
# error "No network application specified"
#endif
@ -155,19 +159,19 @@ int user_start(int argc, char *argv[])
uip_setnetmask("eth0", &addr);
#endif
#if defined(CONFIG_EXAMPLE_UIP_WEBSERVER)
httpd_init();
httpd_listen();
#elif defined(CONFIG_EXAMPLE_UIP_TELNETD)
telnetd_init();
#elif defined(CONFIG_EXAMPLE_UIP_DHCPC)
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
/* Set up the resolver */
resolv_init();
#endif
#if defined(CONFIG_EXAMPLE_UIP_DHCPC)
/* Get the MAC address of the NIC */
uip_getmacaddr("eth0", mac);
/* Set up the resolver and DHCPC modules */
/* Set up the DHCPC modules */
resolv_init();
handle = dhcpc_open(&mac, IFHWADDRLEN);
/* Get an IP address */
@ -182,6 +186,13 @@ int user_start(int argc, char *argv[])
resolv_conf(&ds.dnsaddr);
dhcpc_close(handle);
}
#endif
#if defined(CONFIG_EXAMPLE_UIP_WEBSERVER)
httpd_init();
httpd_listen();
#elif defined(CONFIG_EXAMPLE_UIP_TELNETD)
telnetd_init();
#elif defined(CONFIG_EXAMPLE_UIP_SMTP)
uip_ipaddr(addr.s_addr, 127, 0, 0, 1);
handle = smtp_open();
@ -194,10 +205,9 @@ int user_start(int argc, char *argv[])
}
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
webclient_init();
resolv_init();
uip_ipaddr(addr.s_addr, 195, 54, 122, 204);
addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_DNSADDR);
resolv_conf(&addr);
resolv_query("www.sics.se");
resolv_query(CONFIG_EXAMPLE_UIP_SERVERURL);
#endif
while(1)

View File

@ -121,6 +121,9 @@ struct uip_conn
uint8 timer; /* The retransmission timer (units: half-seconds) */
uint8 nrtx; /* The number of retransmissions for the last
* segment sent */
uint8 data_flags; /* Flags that will be handled by the data_event()
* callback function (see data_event() discussion below).
*/
/* Read-ahead buffering */
@ -143,6 +146,10 @@ struct uip_conn
* UIP_NEWDATA - May be cleared to suppress returning the ACK response.
* (dev->d_len should also be set to zero in this case).
*
*
* The provider of the data_event callback must also set data_flags. This
* will inform the uIP layer which flags are and are not handled by the
* callback.
* accept() is called when the TCP logic has created a connection
* connection_event() is called on any of the subset of connection-related events
*/

View File

@ -266,9 +266,8 @@ extern void uip_setipid(uint16 id);
*
* Note: This function does not guarantee that the sent data will
* arrive at the destination. If the data is lost in the network, the
* application will be invoked with the uip_rexmit_event() event being
* set. The application will then have to resend the data using this
* function.
* application will be invoked with the UIP_REXMIT flag set. The
* application will then have to resend the data using this function.
*
* data A pointer to the data which is to be sent.
*
@ -277,92 +276,6 @@ extern void uip_setipid(uint16 id);
extern void uip_send(struct uip_driver_s *dev, const void *buf, int len);
/* The length of any incoming data that is currently avaliable (if avaliable)
* in the d_appdata buffer.
*
* The test function uip_data() must first be used to check if there
* is any data available at all.
*/
#define uip_datalen(dev) ((dev)->d_len)
/* uIP tests that can be made to determine in what state the current
* connection is, and what the application function should do.
*
* Is new incoming data available?
*
* Will reduce to non-zero if there is new data for the application
* present at the d_appdata pointer. The size of the data is
* avaliable through the d_len element.
*/
#define uip_newdata_event(f) ((f) & UIP_NEWDATA)
/* Has previously sent data been acknowledged?
*
* Will reduce to non-zero if the previously sent data has been
* acknowledged by the remote host. This means that the application
* can send new data.
*/
#define uip_ack_event(f) ((f) & UIP_ACKDATA)
/* Has the connection just been connected?
*
* Reduces to non-zero if the current connenetutils/telnetd/telnetd.cction has been connected to
* a remote host. This will happen both if the connection has been
* actively opened (with uip_connect()) or passively opened (with
* uip_listen()).
*/
#define uip_connected_event(f) ((f) & UIP_CONNECTED)
/* Has the connection been closed by the other end?
*
* Is non-zero if the connection has been closed by the remote
* host. The application may then do the necessary clean-ups.
*/
#define uip_close_event(f) ((f) & UIP_CLOSE)
/* Has the connection been aborted by the other end?
*
* Non-zero if the current connection has been aborted (reset) by the
* remote host.
*/
#define uip_abort_event(f) ((f) & UIP_ABORT)
/* Has the connection timed out?
*
* Non-zero if the current connection has been aborted due to too many
* retransmissions.
*/
#define uip_timeout_event(f) ((f) & UIP_TIMEDOUT)
/* Do we need to retransmit previously data?
*
* Reduces to non-zero if the previously sent data has been lost in
* the network, and the application should retransmit it. The
* application should send the exact same data as it did the last
* time, using the uip_send() function.
*/
#define uip_rexmit_event(f) ((f) & UIP_REXMIT)
/* Is the connection being polled by uIP?
*
* Is non-zero if the reason the application is invoked is that the
* current connection has been idle for a while and should be
* polled.
*
* The polling event can be used for sending data without having to
* wait for the remote host to send data.
*/
#define uip_poll_event(f) ((f) & UIP_POLL)
/* uIP convenience and converting functions.
*
* These functions can be used for converting between different data

View File

@ -146,6 +146,7 @@ static inline void tcp_setup_callbacks(struct uip_conn *conn, FAR struct socket
{
/* Set up the callbacks in the connection */
conn->data_flags = UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT|UIP_CONNECTED;
conn->data_private = (void*)pstate;
conn->data_event = tcp_connect_interrupt;
@ -165,6 +166,7 @@ static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status)
{
/* Make sure that no further interrupts are processed */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;

View File

@ -102,6 +102,7 @@ static uint8 netclose_interrupt(struct uip_driver_s *dev,
{
/* The disconnection is complete */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
sem_post(&pstate->cl_sem);
@ -160,6 +161,7 @@ static inline void netclose_disconnect(FAR struct socket *psock)
sem_init(&state.cl_sem, 0, 0);
conn = psock->s_conn;
conn->data_flags = UIP_NEWDATA|UIP_CLOSE|UIP_ABORT;
conn->data_private = (void*)&state;
conn->data_event = netclose_interrupt;
@ -170,6 +172,7 @@ static inline void netclose_disconnect(FAR struct socket *psock)
/* We are now disconnected */
sem_destroy(&state.cl_sem);
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
}

View File

@ -369,7 +369,7 @@ static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev,
{
/* If new data is available, then complete the read action. */
if (uip_newdata_event(flags))
if ((flags & UIP_NEWDATA) != 0)
{
/* Copy the data from the packet */
@ -391,6 +391,7 @@ static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev,
* Don't allow any further TCP call backs.
*/
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
@ -418,6 +419,7 @@ static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev,
/* Stop further callbacks */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
@ -443,6 +445,7 @@ static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev,
nvdbg("TCP timeout\n");
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
@ -543,7 +546,7 @@ static void recvfrom_udpinterrupt(struct uip_driver_s *dev,
{
/* If new data is available, then complete the read action. */
if (uip_newdata_event(flags))
if ((flags & UIP_NEWDATA) != 0)
{
/* Copy the data from the packet */
@ -860,6 +863,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Set up the callback in the connection */
conn = (struct uip_conn *)psock->s_conn;
conn->data_flags = UIP_NEWDATA|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT;
conn->data_private = (void*)&state;
conn->data_event = recvfrom_tcpinterrupt;
@ -873,6 +877,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Make sure that no further interrupts are processed */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
}

View File

@ -110,7 +110,7 @@ static uint8 send_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uin
* then send it now.
*/
if (pstate->snd_state != STATE_DATA_SENT || uip_rexmit_event(flags))
if (pstate->snd_state != STATE_DATA_SENT || (flags & UIP_REXMIT) != 0)
{
if (pstate->snd_buflen > uip_mss(conn))
{
@ -126,7 +126,7 @@ static uint8 send_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uin
/* Check if all data has been sent and acknowledged */
else if (pstate->snd_state == STATE_DATA_SENT && uip_ack_event(flags))
else if (pstate->snd_state == STATE_DATA_SENT && (flags & UIP_ACKDATA) != 0)
{
/* Yes.. the data has been sent AND acknowledged */
@ -152,6 +152,7 @@ static uint8 send_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uin
/* Don't allow any further call backs. */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
@ -169,6 +170,7 @@ static uint8 send_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uin
{
/* Stop further callbacks */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
@ -301,6 +303,7 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags)
/* Set up the callback in the connection */
conn = (struct uip_conn *)psock->s_conn;
conn->data_flags = UIP_REXMIT|UIP_ACKDATA|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT;
conn->data_private = (void*)&state;
conn->data_event = send_interrupt;
@ -318,6 +321,7 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags)
/* Make sure that no further interrupts are processed */
conn->data_flags = 0;
conn->data_private = NULL;
conn->data_event = NULL;
}

View File

@ -84,7 +84,7 @@ uip_dataevent(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags)
* can have zero-length with UIP_NEWDATA set just to cause an ACK).
*/
if (uip_newdata_event(flags) && dev->d_len > 0)
if ((flags & UIP_NEWDATA) != 0 && dev->d_len > 0)
{
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
/* Allocate a read-ahead buffer to hold the newly received data */
@ -174,7 +174,7 @@ uint8 uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, uint8 fla
if (conn->data_event)
{
/* Perform the callback. Callback function normally returns the input flags,
* however, the implemenation may set one of the following:
* however, the implementation may set one of the following:
*
* UIP_CLOSE - Gracefully close the current connection
* UIP_ABORT - Abort (reset) the current connection on an error that
@ -188,12 +188,17 @@ uint8 uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, uint8 fla
ret = conn->data_event(dev, conn, flags);
}
else
/* If there is no data callback -OR- if the data callback does not handle the
* newdata event, then there is no handler in place to handle new incoming data.
*/
if (!conn->data_event || (conn->data_flags & UIP_NEWDATA) == 0)
{
/* There is no handler to receive new data in place */
/* In either case, we will take a default newdata action */
nvdbg("No listener on connection\n");
ret = uip_dataevent(dev, conn, flags);
ret = uip_dataevent(dev, conn, ret);
}
/* Check if there is a connection-related event and a connection

View File

@ -1,5 +1,5 @@
/****************************************************************************
* dhcpc.c
* netutils/dhcpc/dhcpc.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
@ -103,10 +103,10 @@
struct dhcpc_state_internal
{
struct uip_udp_conn *conn;
const void *mac_addr;
int mac_len;
int sockfd;
char buffer[256];
const void *mac_addr;
int mac_len;
int sockfd;
char buffer[256];
};
struct dhcp_msg

View File

@ -1,4 +1,5 @@
/* uip-resolv.c
/****************************************************************************
* uip-resolv.c
* DNS host name to IP address resolver.
*
* The uIP DNS resolver functions are used to lookup a hostname and

View File

@ -338,7 +338,7 @@ static void newdata(struct uip_driver_s *dev)
{
uint16 len;
len = uip_datalen(dev);
len = dev->d_len;
if (s.state == WEBCLIENT_STATE_STATUSLINE) {
len = parse_statusline(dev, len);
@ -363,7 +363,7 @@ uint8 uip_interrupt_event(struct uip_driver_s *dev, struct uip_conn *conn, uint8
#warning OBSOLETE -- needs to be redesigned
g_return = flags;
if (uip_connected_event(flags))
if ((flags & UIP_CONNECTED) != 0)
{
s.timer = 0;
s.state = WEBCLIENT_STATE_STATUSLINE;
@ -378,33 +378,33 @@ uint8 uip_interrupt_event(struct uip_driver_s *dev, struct uip_conn *conn, uint8
return UIP_ABORT;
}
if (uip_abort_event(flags))
if ((flags & UIP_ABORT) != 0)
{
webclient_aborted();
}
if (uip_timeout_event(flags))
if ((flags & UIP_TIMEDOUT) != 0)
{
webclient_timedout();
}
if (uip_ack_event(flags))
if ((flags & UIP_ACKDATA) != 0)
{
s.timer = 0;
acked(conn);
}
if (uip_newdata_event(flags))
if ((flags & UIP_NEWDATA) != 0)
{
s.timer = 0;
newdata(dev);
}
if (uip_rexmit_event(flags) || uip_newdata_event(flags) || uip_ack_event(flags))
if ((flags & UIP_REXMIT) != 0 || (flags & UIP_NEWDATA) != 0 || (flags & UIP_ACKDATA) != 0)
{
senddata(dev, conn);
}
else if (uip_poll_event(flags))
else if ((flags & UIP_POLL) != 0)
{
++s.timer;
if (s.timer == WEBCLIENT_TIMEOUT)
@ -414,7 +414,7 @@ uint8 uip_interrupt_event(struct uip_driver_s *dev, struct uip_conn *conn, uint8
}
}
if (uip_close_event(flags))
if ((flags & UIP_CLOSE) != 0)
{
if (s.httpflag != HTTPFLAG_MOVED)
{