[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Is this a memory fragmentation problem
From: |
Sergio R. Caprile |
Subject: |
Re: [lwip-users] Is this a memory fragmentation problem |
Date: |
Fri, 18 May 2018 18:50:52 -0300 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
Usually the driver asks for PBUF_POOL, while TCP takes from PBUF_RAM.
Whatever you free in rx callbacks shouldn't mess with tx since they use
different areas.
PBUF_POOL is allocated as memp_malloc(MEMP_PBUF_POOL), which takes
memory from a pool of pbufs defined in the MEMP_ are of lwipopts
PBUF_RAM is allocated as mem_malloc(), which takes memory from a heap of
size MEM_SIZE, which I see rather small (I use 4K), but your data is
small too.
... unless you set otherwise in your lwipopts; but I didn't see that.
Did you ?
My tcp_recv() callback is something like:
if ((p == NULL) || (err != ERR_OK)){
printf("Connection closed by remote end\n");
if(tcp_close(pcb) == ERR_OK){
tcp_recv(pcb, NULL);
}
/* otherwise retry closure at the poll callback but this
has been simplified in 2.0 and I'm too lazy to update */
return ERR_OK;
}
pbuf_copy_partial(p, somewhere, p->tot_len, 0);
tcp_recved(pcb, p->tot_len);
pbuf_free(p);
return ERR_OK;
You have to return ERR_OK on closure, not the err parameter
http://www.nongnu.org/lwip/2_0_x/tcp_8h.html#a780cfac08b02c66948ab94ea974202e8
The tcp_sent() callback is used to resume sending when you could not fit
all your data on a single call to tcp_write. Then you wait for the stack
to tell you when its done and just in case you set up a poll callback to
call you later. You return ERR_OK and do nothing. IIRC you can skip
defining a callback and the stack will stay happy.