Improved read-ahead buffer management
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@430 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
cba8fa9596
commit
a932e62067
@ -268,3 +268,4 @@
|
|||||||
* Implemented send() timeout logic
|
* Implemented send() timeout logic
|
||||||
* Add a skeleton Ethernet device driver (drivers/net/skeleton.c)
|
* Add a skeleton Ethernet device driver (drivers/net/skeleton.c)
|
||||||
* Added C5471 Ethernet device driver (arch/arm/src/c5471/c5471_ethernet.c)
|
* Added C5471 Ethernet device driver (arch/arm/src/c5471/c5471_ethernet.c)
|
||||||
|
* Improved utilization of read-ahead buffers
|
||||||
|
@ -964,6 +964,7 @@ Other memory:
|
|||||||
* Add TELNETD front end to NSH (examples/nsh)
|
* Add TELNETD front end to NSH (examples/nsh)
|
||||||
* Add a skeleton Ethernet device driver (drivers/net/skeleton.c)
|
* Add a skeleton Ethernet device driver (drivers/net/skeleton.c)
|
||||||
* Added C5471 Ethernet device driver (arch/arm/src/c5471/c5471_ethernet.c)
|
* Added C5471 Ethernet device driver (arch/arm/src/c5471/c5471_ethernet.c)
|
||||||
|
* Improved utilization of read-ahead buffers
|
||||||
</pre></ul>
|
</pre></ul>
|
||||||
|
|
||||||
<table width ="100%">
|
<table width ="100%">
|
||||||
|
@ -59,6 +59,45 @@
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: uip_readahead
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Copy as much received data as possible into the readahead buffer
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* This function is called at the interrupt level with interrupts disabled.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
|
||||||
|
static int uip_readahead(struct uip_readahead_s *readahead, uint8 *buf, int len)
|
||||||
|
{
|
||||||
|
int available = CONFIG_NET_TCP_READAHEAD_BUFSIZE - readahead->rh_nbytes;
|
||||||
|
int recvlen = 0;
|
||||||
|
|
||||||
|
if (len > 0 && available > 0)
|
||||||
|
{
|
||||||
|
/* Get the length of the data to buffer. */
|
||||||
|
|
||||||
|
if (len > available)
|
||||||
|
{
|
||||||
|
recvlen = available;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recvlen = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the new appdata into the read-ahead buffer */
|
||||||
|
|
||||||
|
memcpy(&readahead->rh_buffer[readahead->rh_nbytes], buf, recvlen);
|
||||||
|
readahead->rh_nbytes += recvlen;
|
||||||
|
}
|
||||||
|
return recvlen;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: uip_dataevent
|
* Function: uip_dataevent
|
||||||
*
|
*
|
||||||
@ -74,10 +113,6 @@
|
|||||||
static inline uint8
|
static inline uint8
|
||||||
uip_dataevent(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags)
|
uip_dataevent(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags)
|
||||||
{
|
{
|
||||||
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
|
|
||||||
struct uip_readahead_s *readahead;
|
|
||||||
uint16 recvlen;
|
|
||||||
#endif
|
|
||||||
uint8 ret = flags;
|
uint8 ret = flags;
|
||||||
|
|
||||||
/* Is there new data? With non-zero length? (Certain connection events
|
/* Is there new data? With non-zero length? (Certain connection events
|
||||||
@ -87,39 +122,56 @@ uip_dataevent(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags)
|
|||||||
if ((flags & UIP_NEWDATA) != 0 && dev->d_len > 0)
|
if ((flags & UIP_NEWDATA) != 0 && dev->d_len > 0)
|
||||||
{
|
{
|
||||||
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
|
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
|
||||||
/* Allocate a read-ahead buffer to hold the newly received data */
|
struct uip_readahead_s *readahead1;
|
||||||
|
struct uip_readahead_s *readahead2 = NULL;
|
||||||
|
uint16 recvlen = 0;
|
||||||
|
uint8 *buf = dev->d_appdata;
|
||||||
|
int buflen = dev->d_len;
|
||||||
|
|
||||||
readahead = uip_tcpreadaheadalloc();
|
/* First, we need to determine if we have space to buffer the data. This
|
||||||
if (readahead)
|
* needs to be verified before we actually begin buffering the data. We
|
||||||
|
* will use any remaining space in the last allocated readahead buffer
|
||||||
|
* plus as much one additional buffer. It is expected that the size of
|
||||||
|
* readahead buffers are tuned so that one full packet will always fit
|
||||||
|
* into one readahead buffer (for example if the buffer size is 420, then
|
||||||
|
* a readahead buffer of 366 will hold a full packet of TCP data).
|
||||||
|
*/
|
||||||
|
|
||||||
|
readahead1 = (struct uip_readahead_s*)conn->readahead.tail;
|
||||||
|
if ((readahead1 &&
|
||||||
|
(CONFIG_NET_TCP_READAHEAD_BUFSIZE - readahead1->rh_nbytes) > buflen) ||
|
||||||
|
(readahead2 = uip_tcpreadaheadalloc()) != NULL)
|
||||||
{
|
{
|
||||||
/* Get the length of the data to buffer. If the sizes of the
|
/* We have buffer space. Now try to append add as much data as possible
|
||||||
* read-ahead buffers are picked correct, they should always
|
* to the last readahead buffer attached to this connection.
|
||||||
* hold the full received packet.\
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (dev->d_len > CONFIG_NET_TCP_READAHEAD_BUFSIZE)
|
if (readahead1)
|
||||||
{
|
{
|
||||||
recvlen = CONFIG_NET_TCP_READAHEAD_BUFSIZE;
|
recvlen = uip_readahead(readahead1, buf, buflen);
|
||||||
}
|
if (recvlen > 0)
|
||||||
else
|
{
|
||||||
{
|
buf += recvlen;
|
||||||
recvlen = dev->d_len;
|
buflen -= recvlen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the new appdata into the read-ahead buffer */
|
/* Do we need to buffer into the newly allocated buffer as well? */
|
||||||
|
|
||||||
memcpy(readahead->rh_buffer, dev->d_appdata, recvlen);
|
if (readahead2)
|
||||||
readahead->rh_nbytes = recvlen;
|
{
|
||||||
nvdbg("Buffered %d bytes (of %d)\n", recvlen, dev->d_len);
|
(void)uip_readahead(readahead2, buf, buflen);
|
||||||
|
|
||||||
/* Save the readahead buffer in the connection structure where
|
/* Save the readahead buffer in the connection structure where
|
||||||
* it can be found with recv() is called.
|
* it can be found with recv() is called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sq_addlast(&readahead->rh_node, &conn->readahead);
|
sq_addlast(&readahead2->rh_node, &conn->readahead);
|
||||||
|
}
|
||||||
|
|
||||||
/* Indicate that all of the data in the buffer has been consumed */
|
/* Indicate that all of the data in the buffer has been consumed */
|
||||||
|
|
||||||
|
nvdbg("Buffered %d bytes\n", dev->d_len);
|
||||||
dev->d_len = 0;
|
dev->d_len = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user