lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Throttling incoming TCP in receive callback using raw API


From: Bruce Sutherland
Subject: [lwip-users] Throttling incoming TCP in receive callback using raw API
Date: Thu, 23 Oct 2008 10:56:31 +0800

Hello all.

In our application, we are using the raw API to provide a serial device
server. We listen for TCP connections on a 100 Base Tx Ethernet interface,
and retransmit all incoming data on the TCP connection out on an RS-232
serial port.

In our TCP receive callback, data is simply copied from the pbufs provided
by lwip, into a serial ring buffer. As the serial port is much slower than
the Ethernet port, we need a way to inform lwip that we cannot receive more
data when the serial buffer is full. What is the mechanism to do this?
Should I delay calling tcp_recved in the case that the serial ring buffer is
too full? If so, when will my receive callback be called again? Is there
some better way to achieve this?

Our current implementation appears below, which calls tcp_recved for all
data as it arrives, and just throws an assertion if the serial ring buffer
is too full to fit the data.

Thank you,

Bruce.


err_t StreamRecvCallback(void *arg, struct tcp_pcb *tpcb, struct pbuf* p,
err_t err)
{
    struct pbuf *q;
    if (NULL != tpcb && NULL != p)
    {
        Core_Validate_Assert(Core_RingBuf_GetFree(RxRing) >= p->tot_len);
        for(q = p; q != NULL; q = q->next)
        {
            rq = q->payload;
            for (j = 0; j < q->len; j++)
            {
                Core_RingBuf_Write(RxRing, rq[j]);                
            }
        }
        tcp_recved(tpcb, p->tot_len);        
        pbuf_free(p);   // TODO: make sure this frees the whole chain, not
just the first link        
    }  
    else
    {
        ResetStream(*(uint16_t*)arg - NETDRV_LWIPWRAP_STREAM_OFFSET);
    }
    return ERR_OK;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]