All of Jason Jaing's write buffering logic has been incorporated, but not even yet built

This commit is contained in:
Gregory Nutt 2014-01-14 08:30:35 -06:00
parent 375b683860
commit f034d84ea1
4 changed files with 61 additions and 24 deletions

View File

@ -278,7 +278,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn,
#endif
{
FAR struct uip_write_s *segment;
FAR void *sndbuff;
FAR void *sndbuf;
size_tsndlen;
/* Get the amount of data that we can send in the next packet */
@ -286,8 +286,8 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn,
segment = (FAR struct uip_write_s*)sq_peek(&conn->write_q);
if (segment)
{
sndbuff = segment->wb_buffer;
sndlen = segment->wb_nbytes;
sndbuf = segment->wb_buffer;
sndlen = segment->wb_nbytes;
DEBUGASSERT(sndlen <= uip_mss(conn));
@ -318,7 +318,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn,
* actually happen until the polling cycle completes).
*/
uip_send(dev, sndbuff, sndlen);
uip_send(dev, sndbuf, sndlen);
/* Remember how much data we send out now so that we know
* when everything has been acknowledged. Just increment
@ -332,7 +332,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn,
{
conn->unacked += sndlen;
conn->sent += sndlen;
}
}
/* Increment the retransmission counter before expiration.
* NOTE we will not calculate the retransmission timer
@ -493,7 +493,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
segment->wb_seqno = (unsigned)-1;
segment->wb_nrtx = 0;
if (len-completed > CONFIG_NET_TCP_WRITE_BUFSIZE)
if (len - completed > CONFIG_NET_TCP_WRITE_BUFSIZE)
{
cnt = CONFIG_NET_TCP_WRITE_BUFSIZE;
}
@ -503,7 +503,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
}
segment->wb_nbytes = cnt;
memcpy(segment->wb_buffer, (char*)buf+completed, cnt);
memcpy(segment->wb_buffer, (char*)buf + completed, cnt);
completed += cnt;
/* send_interrupt() will refer to all the write buffer by

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/uip/uip_tcpappsend.c
*
* Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2010, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
@ -131,6 +131,9 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn,
else
{
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
DEBUGASSERT(dev->d_sndlen >= 0 && dev->d_sndlen <= conn->mss);
#else
/* If d_sndlen > 0, the application has data to be sent. */
if (dev->d_sndlen > 0)
@ -138,7 +141,7 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn,
/* Remember how much data we send out now so that we know
* when everything has been acknowledged. Just increment the amount
* of data sent. This will be needed in sequence number calculations
* and we know that this is not a re-tranmission. Retransmissions
* and we know that this is not a re-transmission. Retransmissions
* do not go through this path.
*/
@ -151,9 +154,10 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn,
DEBUGASSERT(dev->d_sndlen <= conn->mss);
}
conn->nrtx = 0;
#endif
/* Then handle the rest of the operation just as for the rexmit case */
conn->nrtx = 0;
uip_tcprexmit(dev, conn, result);
}
}
@ -189,7 +193,11 @@ void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn,
* new data in it, we must send out a packet.
*/
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
if (dev->d_sndlen > 0)
#else
if (dev->d_sndlen > 0 && conn->unacked > 0)
#endif
{
/* We always set the ACK flag in response packets adding the length of
* the IP and TCP headers.

View File

@ -2,7 +2,7 @@
* net/uip/uip_tcpinput.c
* Handling incoming TCP input
*
* Copyright (C) 2007-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
@ -358,7 +358,11 @@ found:
* data (unacked).
*/
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
unackseq = conn->isn + conn->sent;
#else
unackseq = uip_tcpaddsequence(conn->sndseq, conn->unacked);
#endif
/* Get the sequence number of that has just been acknowledged by this
* incoming packet.
@ -383,12 +387,16 @@ found:
{
/* What would it mean if ackseq > unackseq? The peer has ACKed
* more bytes than we think we have sent? Someone has lost it.
* Complain and reset the number of outstanding, unackowledged
* Complain and reset the number of outstanding, unacknowledged
* bytes
*/
nlldbg("ERROR: ackseq[%08x] > unackseq[%08x]\n", ackseq, unackseq);
conn->unacked = 0;
if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
{
nlldbg("ERROR: conn->sndseq %d, conn->unacked %d\n",
uip_tcpgetsequence(conn->sndseq), conn->unacked);
goto reset;
}
}
/* Update sequence number to the unacknowledge sequence number. If
@ -450,10 +458,15 @@ found:
if ((flags & UIP_ACKDATA) != 0)
{
conn->tcpstateflags = UIP_ESTABLISHED;
conn->unacked = 0;
nllvdbg("TCP state: UIP_ESTABLISHED\n");
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
conn->isn = uip_tcpgetsequence(pbuf->ackno);
uip_tcpsetsequence(conn->sndseq, conn->isn);
conn->sent = 0;
#endif
conn->unacked = 0;
flags = UIP_CONNECTED;
nllvdbg("TCP state: UIP_ESTABLISHED\n");
if (dev->d_len > 0)
{
@ -539,12 +552,18 @@ found:
conn->tcpstateflags = UIP_ESTABLISHED;
memcpy(conn->rcvseq, pbuf->seqno, 4);
nllvdbg("TCP state: UIP_ESTABLISHED\n");
uip_incr32(conn->rcvseq, 1);
conn->unacked = 0;
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
conn->isn = uip_tcpgetsequence(pbuf->ackno);
uip_tcpsetsequence(conn->sndseq, conn->isn);
#endif
dev->d_len = 0;
dev->d_sndlen = 0;
nllvdbg("TCP state: UIP_ESTABLISHED\n");
result = uip_tcpcallback(dev, conn, UIP_CONNECTED | UIP_NEWDATA);
uip_tcpappsend(dev, conn, result);
return;
@ -726,8 +745,8 @@ found:
case UIP_FIN_WAIT_1:
/* The application has closed the connection, but the remote host
* hasn't closed its end yet. Thus we do nothing but wait for a
* FIN from the other side.
* hasn't closed its end yet. Thus we stay in the FIN_WAIT_1 state
* until we receive a FIN from the remote.
*/
if (dev->d_len > 0)
@ -768,6 +787,7 @@ found:
uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
return;
}
goto drop;
case UIP_FIN_WAIT_2:
@ -793,6 +813,7 @@ found:
uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
return;
}
goto drop;
case UIP_TIME_WAIT:

View File

@ -115,11 +115,12 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
* out.
*/
if (conn->tcpstateflags == UIP_TIME_WAIT || conn->tcpstateflags == UIP_FIN_WAIT_2)
if (conn->tcpstateflags == UIP_TIME_WAIT ||
conn->tcpstateflags == UIP_FIN_WAIT_2)
{
/* Increment the connection timer */
(conn->timer) += hsec;
conn->timer += hsec;
if (conn->timer >= UIP_TIME_WAIT_TIMEOUT)
{
conn->tcpstateflags = UIP_CLOSED;
@ -133,7 +134,8 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
* retransmit.
*/
if (conn->unacked > 0)
if (conn->unacked > 0 &&
(conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
{
/* The connection has outstanding data */
@ -151,10 +153,16 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
/* Should we close the connection? */
if (conn->nrtx == UIP_MAXRTX ||
if (
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
conn->expired > 0 ||
#else
conn->nrtx == UIP_MAXRTX ||
#endif
((conn->tcpstateflags == UIP_SYN_SENT ||
conn->tcpstateflags == UIP_SYN_RCVD) &&
conn->nrtx == UIP_MAXSYNRTX))
conn->nrtx == UIP_MAXSYNRTX)
)
{
conn->tcpstateflags = UIP_CLOSED;
nllvdbg("TCP state: UIP_CLOSED\n");