From 0cc9b5ef69aa200c2610f3e87281fe9aa9d7d389 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 19 Nov 2007 23:09:39 +0000 Subject: Add TCP readahead logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@387 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/include/net/uip/uip-arch.h | 2 +- nuttx/include/net/uip/uip-lib.h | 4 +- nuttx/include/net/uip/uip.h | 42 ++++++++++--- nuttx/include/net/uip/uipopt.h | 130 ++++++++++----------------------------- 4 files changed, 71 insertions(+), 107 deletions(-) (limited to 'nuttx/include/net/uip') diff --git a/nuttx/include/net/uip/uip-arch.h b/nuttx/include/net/uip/uip-arch.h index 8d2b15d40..b4f21fb64 100644 --- a/nuttx/include/net/uip/uip-arch.h +++ b/nuttx/include/net/uip/uip-arch.h @@ -116,7 +116,7 @@ struct uip_driver_s * } */ - uint8 d_buf[UIP_BUFSIZE + 2]; + uint8 d_buf[CONFIG_NET_BUFSIZE + 2]; /* d_appdata points to the location where application data can be read from * or written into a packet. diff --git a/nuttx/include/net/uip/uip-lib.h b/nuttx/include/net/uip/uip-lib.h index d5799ee56..307a6b277 100644 --- a/nuttx/include/net/uip/uip-lib.h +++ b/nuttx/include/net/uip/uip-lib.h @@ -47,7 +47,7 @@ ****************************************************************************/ #include -#include +#include #include /**************************************************************************** @@ -106,6 +106,6 @@ extern int uip_setnetmask(const char *ifname, const struct in_addr *addr); /* Generic server logic */ -extern void uip_server(uint16 portno, main_t handler, int stacksize); +extern void uip_server(uint16 portno, pthread_startroutine_t handler, int stacksize); #endif /* __UIPLIB_H__ */ diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h index 46e6907e4..150f594ce 100644 --- a/nuttx/include/net/uip/uip.h +++ b/nuttx/include/net/uip/uip.h @@ -112,7 +112,7 @@ * snprintf(dev->d_appdata, UIP_APPDATA_SIZE, "%u\n", i); */ -#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#define UIP_APPDATA_SIZE (CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) #define UIP_PROTO_ICMP 1 #define UIP_PROTO_TCP 6 @@ -183,6 +183,12 @@ struct uip_conn uint8 nrtx; /* The number of retransmissions for the last * segment sent */ + /* Read-ahead buffering */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 + sq_queue_t readahead; +#endif + /* Higher level logic can retain application specific information * in the following: * @@ -212,12 +218,27 @@ struct uip_conn void (*connection_event)(struct uip_conn *conn, uint8 flags); }; +/* The following structure is used to handle read-ahead buffering for TCP + * connection. When incoming TCP data is received while no application is + * listening for the data, that data will be retained in these read-ahead + * buffers so that no data is lost. + */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +struct uip_readahead_s +{ + sq_entry_t rh_node; /* Supports a singly linked list */ + uint16 rh_nbytes; /* Number of bytes available in this buffer */ + uint8 rh_buffer[CONFIG_NET_TCP_READAHEAD_BUFSIZE]; +}; +#endif + #ifdef CONFIG_NET_UDP /* Representation of a uIP UDP connection */ struct uip_udp_conn { - dq_entry_t node; /* Implements a doubly linked list */ + dq_entry_t node; /* Supports a doubly linked list */ uip_ipaddr_t ripaddr; /* The IP address of the remote peer */ uint16 lport; /* The local port number in network byte order */ uint16 rport; /* The remote port number in network byte order */ @@ -493,11 +514,11 @@ extern struct uip_stats uip_stat; * TCP/IP stack. */ -void uip_initialize(void); +extern void uip_initialize(void); /* This function may be used at boot time to set the initial ip_id.*/ -void uip_setipid(uint16 id); +extern void uip_setipid(uint16 id); /* uIP application functions * @@ -559,7 +580,7 @@ extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr) * port A 16-bit port number in network byte order. */ -int uip_listen(uint16 port); +extern int uip_listen(uint16 port); /* Stop listening to the specified port. * @@ -569,7 +590,7 @@ int uip_listen(uint16 port); * port A 16-bit port number in network byte order. */ -int uip_unlisten(uint16 port); +extern int uip_unlisten(uint16 port); /* Check if a connection has outstanding (i.e., unacknowledged) data */ @@ -598,7 +619,14 @@ int uip_unlisten(uint16 port); * len The maximum amount of data bytes to be sent. */ -void uip_send(struct uip_driver_s *dev, const void *buf, int len); +extern void uip_send(struct uip_driver_s *dev, const void *buf, int len); + +/* Access to TCP read-ahead buffers */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +extern struct uip_readahead_s *uip_tcpreadaheadalloc(void); +extern void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); +#endif /* CONFIG_NET_NTCP_READAHEAD_BUFFERS */ /* The length of any incoming data that is currently avaliable (if avaliable) * in the d_appdata buffer. diff --git a/nuttx/include/net/uip/uipopt.h b/nuttx/include/net/uip/uipopt.h index 3a3fc68f2..b50884703 100644 --- a/nuttx/include/net/uip/uipopt.h +++ b/nuttx/include/net/uip/uipopt.h @@ -69,22 +69,6 @@ * Public Type Definitions ****************************************************************************/ -/* Static configuration options */ - -/* Ping IP address asignment. - * - * uIP uses a "ping" packets for setting its own IP address if this - * option is set. If so, uIP will start with an empty IP address and - * the destination IP address of the first incoming "ping" (ICMP echo) - * packet will be used for setting the hosts IP address. - */ - -#ifdef CONFIG_NET_PINGADDRCONF -#define UIP_PINGADDRCONF CONFIG_NET_PINGADDRCONF -#else /* CONFIG_NET_PINGADDRCONF */ -#define UIP_PINGADDRCONF 0 -#endif /* CONFIG_NET_PINGADDRCONF */ - /* IP configuration options */ /* The IP TTL (time to live) of IP packets sent by uIP. @@ -92,7 +76,7 @@ * This should normally not be changed. */ -#define UIP_TTL 64 +#define UIP_TTL 64 /* Turn on support for IP packet reassembly. * @@ -100,7 +84,7 @@ * requires an additonal amount of RAM to hold the reassembly buffer * and the reassembly code size is approximately 700 bytes. The * reassembly buffer is of the same size as the d_buf buffer - * (configured by UIP_BUFSIZE). + * (configured by CONFIG_NET_BUFSIZE). * * Note: IP packet reassembly is not heavily tested. */ @@ -116,26 +100,12 @@ /* UDP configuration options */ -/* Toggles if UDP checksums should be used or not. - * - * Note: Support for UDP checksums is currently not included in uIP, - * so this option has no function. - */ +/* The maximum amount of concurrent UDP connection, Default: 10 */ -#ifdef CONFIG_NET_UDP_CHECKSUMS -# define UIP_UDP_CHECKSUMS CONFIG_NET_UDP_CHECKSUMS -#else -# define UIP_UDP_CHECKSUMS 0 +#ifndef CONFIG_NET_UDP_CONNS +# define CONFIG_NET_UDP_CONNS 10 #endif -/* The maximum amount of concurrent UDP connections. */ - -#ifdef CONFIG_NET_UDP_CONNS -# define UIP_UDP_CONNS CONFIG_NET_UDP_CONNS -#else /* CONFIG_NET_UDP_CONNS */ -# define UIP_UDP_CONNS 10 -#endif /* CONFIG_NET_UDP_CONNS */ - /* TCP configuration options */ /* The maximum number of simultaneously open TCP connections. @@ -145,11 +115,9 @@ * connection requires approximatly 30 bytes of memory. */ -#ifndef CONFIG_NET_MAX_CONNECTIONS -# define UIP_CONNS 10 -#else /* CONFIG_NET_MAX_CONNECTIONS */ -# define UIP_CONNS CONFIG_NET_MAX_CONNECTIONS -#endif /* CONFIG_NET_MAX_CONNECTIONS */ +#ifndef CONFIG_NET_TCP_CONNS +# define CONFIG_NET_TCP_CONNS 10 +#endif /* The maximum number of simultaneously listening TCP ports. * @@ -157,10 +125,8 @@ */ #ifndef CONFIG_NET_MAX_LISTENPORTS -# define UIP_LISTENPORTS 20 -#else /* CONFIG_NET_MAX_LISTENPORTS */ -# define UIP_LISTENPORTS CONFIG_NET_MAX_LISTENPORTS -#endif /* CONFIG_NET_MAX_LISTENPORTS */ +# define CONFIG_NET_MAX_LISTENPORTS 20 +#endif /* Determines if support for TCP urgent data notification should be * compiled in. @@ -169,14 +135,14 @@ * very seldom would be required. */ -#define UIP_URGDATA 0 +#define UIP_URGDATA 0 /* The initial retransmission timeout counted in timer pulses. * * This should not be changed. */ -#define UIP_RTO 3 +#define UIP_RTO 3 /* The maximum number of times a segment should be retransmitted * before the connection should be aborted. @@ -184,7 +150,7 @@ * This should not be changed. */ -#define UIP_MAXRTX 8 +#define UIP_MAXRTX 8 /* The maximum number of times a SYN segment should be retransmitted * before a connection request should be deemed to have been @@ -193,15 +159,15 @@ * This should not need to be changed. */ -#define UIP_MAXSYNRTX 5 +#define UIP_MAXSYNRTX 5 /* The TCP maximum segment size. * * This is should not be to set to more than - * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. + * CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. */ -#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#define UIP_TCP_MSS (CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) /* The size of the advertised receiver's window. * @@ -211,9 +177,7 @@ */ #ifndef CONFIG_NET_RECEIVE_WINDOW -# define UIP_RECEIVE_WINDOW UIP_TCP_MSS -#else -# define UIP_RECEIVE_WINDOW CONFIG_NET_RECEIVE_WINDOW +# define CONFIG_NET_RECEIVE_WINDOW UIP_TCP_MSS #endif /* How long a connection should stay in the TIME_WAIT state. @@ -232,10 +196,8 @@ * have many connections from the local network. */ -#ifdef CONFIG_NET_ARPTAB_SIZE -# define UIP_ARPTAB_SIZE CONFIG_NET_ARPTAB_SIZE -#else -# define UIP_ARPTAB_SIZE 8 +#ifndef CONFIG_NET_ARPTAB_SIZE +# define CONFIG_NET_ARPTAB_SIZE 8 #endif /* The maxium age of ARP table entries measured in 10ths of seconds. @@ -255,23 +217,21 @@ * TCP throughput, larger size results in higher TCP throughput. */ -#ifndef CONFIG_NET_BUFFER_SIZE -# define UIP_BUFSIZE 400 -#else /* CONFIG_NET_BUFFER_SIZE */ -# define UIP_BUFSIZE CONFIG_NET_BUFFER_SIZE -#endif /* CONFIG_NET_BUFFER_SIZE */ +#ifndef CONFIG_NET_BUFSIZE +# define CONFIG_NET_BUFSIZE 400 +#endif -/* Broadcast support. - * - * This flag configures IP broadcast support. This is useful only - * together with UDP. - */ +/* Number of TCP read-ahead buffers (may be zero) */ + +#ifndef CONFIG_NET_NTCP_READAHEAD_BUFFERS +# define CONFIG_NET_NTCP_READAHEAD_BUFFERS 4 +#endif -#ifndef CONFIG_NET_BROADCAST -# define UIP_BROADCAST 0 -#else /* CONFIG_NET_BROADCAST */ -# define UIP_BROADCAST CONFIG_NET_BROADCAST -#endif /* CONFIG_NET_BROADCAST */ +/* The size of the TCP read buffer size */ + +#ifndef CONFIG_NET_TCP_READAHEAD_BUFSIZE +# define CONFIG_NET_TCP_READAHEAD_BUFSIZE UIP_TCP_MSS +#endif /* The link level header length. * @@ -282,32 +242,8 @@ #ifdef CONFIG_NET_LLH_LEN # define UIP_LLH_LEN CONFIG_NET_LLH_LEN -#else /* CONFIG_NET_LLH_LEN */ -# define UIP_LLH_LEN 14 -#endif /* CONFIG_NET_LLH_LEN */ - -/* CPU architecture configuration - * - * The CPU architecture configuration is where the endianess of the - * CPU on which uIP is to be run is specified. Most CPUs today are - * little endian, and the most notable exception are the Motorolas - * which are big endian. The CONFIG_ENDIAN_BIG macro should be changed - * if uIP is to be run on a big endian architecture. - */ - -/* The byte order of the CPU architecture on which uIP is to be run. - * - * This option can be either CONFIG_ENDIAN_BIG (Motorola byte order) or - * default little endian byte order (Intel byte order). - */ - -#define UIP_BIG_ENDIAN 1234 -#define UIP_LITTLE_ENDIAN 3412 - -#ifdef CONFIG_ENDIAN_BIG -# define UIP_BYTE_ORDER UIP_BIG_ENDIAN #else -# define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN +# define UIP_LLH_LEN 14 #endif /**************************************************************************** -- cgit v1.2.3