|
From: | Noam Weissman |
Subject: | Re: [lwip-users] Questions about how to get a robust lwIP TCP Raw API server application. |
Date: | Wed, 4 Nov 2015 12:17:03 +0000 |
Hi, Do you use an OS or is this all of your code ? Noam.
From: lwip-users-bounces+address@hidden [mailto:lwip-users-bounces+address@hidden
On Behalf Of Dinesh Pandey Hi Naom, I guess we are trying to say the same thing. Just to be clear, this is how I write the main loop: while(1) ethernetif_input(); sys_check_timeouts(); my_own_poll(); } my_own_poll() checks for external inputs and internal states and calls tcp_write if needed. The receive callback simply updates the state (or stores data) for my_own_poll to check and do its job. Cheers DP
On Wed, Nov 4, 2015 at 12:40 PM, Noam Weissman <address@hidden> wrote: Hi DP, If you mean calling a function and handling data out of the callback itself but from the same context It is OK I mean for example: err_t foo(void *arg, struct tcp_pcb *pcb) { Return tcp_write(pcb, &Data[DataSent], SendData, TCP_WRITE_FLAG_COPY);
} err_t tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pBuf, err_t err) { Some code . . . Then call : foo(arg, pcb); } In the above pseudo code you handle a tcp_write but it is in the same context of the callback.
This is OK. The problem arises if you call tcp_write from a different task !! If that happens it seems to work but if you transfer lots of data you will start seeing strange behavior. I have noticed out of memory problems (TCP stack memory). The reason is that LwIP has its own internal housekeeping and if you call LwIP functions outside
of the TCP stack context this housekeeping will fail as it is not synchronized with the code from a different task. Hope that helped. BR, Noam. From: lwip-users-bounces+noam=address@hidden
[mailto:lwip-users-bounces+noam=address@hidden]
On Behalf Of Dinesh Pandey "Ok for the write outside of the receive callback. But is it safe and robust?" Never thought about it. I have always called tcp_write outside of the receive callback. I can't see any problem as long as everything is done in the same thread. tcp_write only queues
up the data for writing. tcp_output flushes out the data. I doubt calling it inside the receive callback is any different from calling it outside.
Not sure what you are trying to do here. If you want to stop accepting new connections, do a tcp_close on the listener (the PCB on which you did bind and listen). Cheers DP On Tue, Nov 3, 2015 at 11:23 PM, bom <address@hidden> wrote: Hi and thank you for your fast answer! Sent from the lwip-users mailing list archive at Nabble.com.
|
[Prev in Thread] | Current Thread | [Next in Thread] |