Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc/faq: tcpCleanup #4314

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions doc/faq/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,31 @@ This error may pop up after switching between
`stable <https://github.com/esp8266/Arduino#stable-version->`__ esp8266
/ Arduino package installations, or after upgrading the package version
:doc:`Read more <a04-board-generic-is-unknown>`.


How to clear TCP PCBs in time-wait state ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is needed with lwIP-v1.4, less needed with lwIP-v2 but timeout is still
too high.

Time-wait PCB state helps TCP not confusing two consecutive connections with the
same (s-ip,s-port,d-ip,d-port) when the first is already closed but still
having duplicate packets lost in internet arriving later during the second.
Artificially clearing them is a workaround to help saving precious heap.

The following lines are compatible with both lwIP versions:

.. code:: cpp

// no need for #include
struct tcp_pcb;
extern struct tcp_pcb* tcp_tw_pcbs;
extern "C" void tcp_abort (struct tcp_pcb* pcb);

void tcpCleanup (void) {
while (tcp_tw_pcbs)
tcp_abort(tcp_tw_pcbs);
}

Ref. `#1923 <https://github.com/esp8266/Arduino/issues/1923>`__