lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] lwIP hangs after sending to much data


From: brak brak2
Subject: [lwip-users] lwIP hangs after sending to much data
Date: Mon, 4 Jul 2011 11:42:05 +0200

Hi,

I write a server TCP/IP application with the lwIP stack. I have this
application for two microcontrollers. Basically application is the
same on two microcontrollers (except lwIP port) and I facing the same
problem on both of them. On the Stellaris LM3S6911 the problem was at
the beginning of code writing but somehow it's gone (or hidden). On
the LPC1769 the problem appears every time. Then I try to send too
much data at a time transmission hangs.  To send data I use function
(only part shown):

int HttpSendData(void)
{
...
while(xLength)//petla obu buforow
{
        int maxSend = tcp_sndbuf(HTTP_Pcb);
        //if (maxSend > 500) maxSend = 500;
        //if (maxSend > 100) maxSend = 100;
        SentDataLength = 0;
        SomethingSent = 0;

        while(xLength)//petla bierzacego bufora
        {
                int len;
                len = maxSend < xLength ? maxSend : xLength;
        
                err = tcp_write(HTTP_Pcb, xBuffer, len, 0);
                        
                if (err != ERR_OK)
                {
                        if (err == ERR_MEM)
                        {                               
                                maxSend = len / 2;
                                
                                if (maxSend < 4)
                                {
                                        break;
                                }
                        }
                        else return 1;
                }
...
if (SomethingSent)
{
        err = tcp_output(HTTP_Pcb);
        if (err)
        {
                ...
        }
}
...
}

tcp_write function is called as far as maxSend >= 4. The rest of data
is being send later, after ack in tcp_sent callback function or retry
in tcp_poll callback function.
When I doesn't limit data passed to tcp_write then HttpSendData
function is calling tcp_output after passing 5201 bytes to tcp_write
(whole buffer was sent). After this tcp_sent callback is never called.
tcp_poll callback is calling HttpSendData function but there is no
data to be send (this is correct). Server's waiting for client
response but it never comes, because client didn't get all data.
After closing connection be client I get LAST_ACK state in poll
callback. After closing connection be server (timeout) I get
FIN_WAIT_1 state in poll callback.
I checked the TCP/IP transmission with IP tools program. No
application data was send from lwIP. After connection established
(SYN, SYN+ACK) clients sends request and lwIP response with
SYN+ACK!?!. Client sends request again and lwIP ACK it. But then
client send FIN flag and lwIP RST flag - but lwIP stack doesn't pass
this information to my application layer.

When I limit an among of data passed to tcp_write in one call to 500
bytes then HttpSendData function is calling tcp_output after passing
4500 bytes to tcp_write (). Just as there were no next 500 and 201
bytes of space available in memory. It tries to pass 500, 250, 125,
62, 31, 15, 7 bytes without effect (ERR_MEM). TCP/IP transmission
looks just like I described above.

When I limit an among of data pass to tcp_write to 100 bytes program
works fine. But HttpSendData function is calling tcp_output after
passing 1450 bytes to tcp_write. Just as there were no space avaiable
in memory. It tries to pass  100, 50 (accepted, ERR_OK) 50, 25, 12, 6
bytes without effect (ERR_MEM). After writing 1540 bytes tcp_output is
called. Then the tcp_sent callback is being called and it calls
HttpSendData again to send more data. So program works fine but slower
then I want.

When I make maxSend = 200 then there is 2600 bytes of data passed to
tcp_write before tcp_output is called but lwIP sends only one frame
with 1140 bytes of data but this data is not correct (this data should
be send in second frame).

It looks like there is only space for one ethernet frame. Or maybe
there is a problem with creating pbufs?

How to solve this problem?

I use lwIP 1.3.2 and recently 1.4.0 – the problem is the same.

What is PBUF_LINK_HLEN and how it's correlated with ETH_PAD_SIZE?

I havde defined:
#define NO_SYS                          1
#define MEM_SIZE                        (12 * 1024)
#define MEMP_NUM_PBUF                     24
#define MEMP_NUM_UDP_PCB                1
#define MEMP_NUM_TCP_PCB                  3
#define MEMP_NUM_TCP_PCB_LISTEN         2
#define PBUF_POOL_SIZE                    24
#define TCP_WND                         4096//6000
#define TCP_MSS                         1460 //1500
#define TCP_SND_BUF                     (4 * TCP_MSS)

#define PBUF_LINK_HLEN                  16
#define PBUF_POOL_BUFSIZE               256

//#define ETH_PAD_SIZE                    2           //on LM3S6911
this is 2, On LPC1769 this is not defined.


Best regards
Thomas



reply via email to

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