lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Running out of memory


From: JM
Subject: Re: [lwip-users] Running out of memory
Date: Mon, 30 May 2011 17:42:51 -0700 (PDT)

I think I may have figured it out.  It's amazing how posting about a problem seems to help solve it.  It's not like I didn't spend a considerable amount of time before posting. 

Somehow "some data" was getting created more than once, so I simply put a check in to not allow multiple calls to http_recv() to generate "some data" more than once before the TCP send buffer is empty. 

--- On Mon, 5/30/11, JM <address@hidden> wrote:

From: JM <address@hidden>
Subject: [lwip-users] Running out of memory
To: address@hidden
Date: Monday, May 30, 2011, 4:56 PM

Sometimes when I call tcp_write() it returns ERR_MEM, even though it's not consistent and I'm always sending the same data.  Try to stay with me, as I want to explain how I get there.  I'm using version 1.3.2, no RTOS.

lwIP obtains an IP address, consistently.  Then before making any other connections or Tx/Rx any other data, I do this to listen on port 80. 

      listen_pcb = tcp_new();
      tcp_bind(listen_pcb, IP_ADDR_ANY, 80);
      listen_pcb = tcp_listen(listen_pcb);
      tcp_accept(listen_pcb, http_accept);


and have these functions:

err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
    tcp_recv(pcb, http_recv);
    tcp_err(pcb, conn_err);
    tcp_sent(pcb, http_sent);
    return 0;
}


I have a conn_err() function but it isn't reporting problems. 


err_t http_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
    if(all bytes have been sent)
    {
       tcp_close(pcb);
    }
    return 0;
}


err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
    if(p->payload contains a GET from browser)
    {
        tcp_recved(pcb, p->tot_len);
        pbuf_free(p);

        errcode = tcp_write(pcb, some data, some data length, 0);
        tcp_output(pcb);
    }
    else
    {
        tcp_recved(pcb, p->tot_len);
        pbuf_free(p);
        tcp_close(pcb);
    }
}

"some data" is always the same 7903 bytes.  All I'm doing is putting the device's IP address into Firefox (or IE), it sends a GET, and http_recv() responds with a very simple webpage.  No graphics, nothing fancy.  But this isn't about webpages necessarily.  Randomly, errcode will return ERR_MEM.  It's simply doing the same thing each time.  Sometimes it's occurs after loading the webpage the first time, sometimes after the 2nd time, sometimes even after 12 times. 

I've inserted some code that displays pcb->snd_queuelen and pcb->snd_buf before calling
tcp_write().  Normally pcb->snd_queuelen is 0 and pcb->snd_buf is 14600.  But before tcp_write() returns ERR_MEM, pcb->snd_queuelen is 12 and pcb->snd_buf is 6697. 

It's clear to see that there isn't enough memory when this occurs, and it's filled with exactly one instance of "some data" (14600 - 7903 = 6697), but why isn't it being cleared out, and why does it sometimes occur before sending anything at all?

This isn't being done over the Internet, just on a home LAN.  Am I doing something wrong, or is this totally unexplainable?  If I use Wireshark on it, the captures of a good transaction look exactly like a bad one, except the bad one is truncated, I suppose at the point where it ran out of memory.



-----Inline Attachment Follows-----

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

reply via email to

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