lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Again confused about tcp_recved() and pbuf_free()


From: Giuseppe Modugno
Subject: Re: [lwip-users] Again confused about tcp_recved() and pbuf_free()
Date: Tue, 26 Feb 2019 09:39:42 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

Il 25/02/2019 20:23, address@hidden ha scritto:
Am 23.02.2019 um 10:20 schrieb Giuseppe Modugno:
I know, this is a hot topic and many times this was explaied in the list and in doc/rawapi.txt, however now I'm in trouble understanding this.

tcp_recved() is related to the TCP window size of the receiver: "The purpose is to advertise a larger window when the data has been processed.". Isn't the TCP window size fixed to TCP_WND macro? Does it mean that the window size increases every time tcp_recved() is called from the application? I don't think, otherwise the window size increases continuously during a connection.

The window has a more or less fixed total size. But it changes with each segment sent: for every byte sent (and ACKed), it decrease. The receiver is responsible to "reopen" the window by sending an appropriate window size with its ACK segments. lwIP does this for you, but you have to tell it when you are ready to accept more data. This is what 'tcp_recved()' does.

What are the situations when it should be better to not call tcp_recved() in recv() callback()? Here the application has the received data, can process and free the pbufs or can avoid freeing the pbufs to wait for additional data. In both cases I think the application should call tcp_recved().

If you need to process the received data further at slower speed, it's better to not call tcp_recved() right away. For example if you're programming into slow flash, calling tcp_recved after the bytes are programmed ensures the client does not send faster than you can program.

In this case you don't free the pbuf, because data is being written to the Flash. So it seems to me that when you free the pbuf (you have processed the incoming data), you can call tcp_recved(). If you don't free the pbuf, you haven't processed the data yet, so you don't call tcp_recved().

I don't understand when the two things can be different.




reply via email to

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