Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

FR: Allow configuring LwIP's keepalives #114

Closed
positron96 opened this issue Feb 23, 2021 · 6 comments · May be fixed by #120
Closed

FR: Allow configuring LwIP's keepalives #114

positron96 opened this issue Feb 23, 2021 · 6 comments · May be fixed by #120
Labels

Comments

@positron96
Copy link

Hi.
Is it possible to add support for TCP keepalives (and methods to enable/disable/configure them)? As I understand, LwIP has this functionality and it can be enabled on per-socket basis (I just don't know if it's compiled into ESP32 core).

You see, it's not uncommon in embedded world to just unplug the device from power, in this case a TCP connection will be hanging on the other side and some non-trivial logic would be required to detect and close it. I am testing an application with AsyncServer on one ESP32 and long-lasting TCP connection to WiFiClient on other ESP32, and this ESP32 can be unplugged from power without proper termination. In this case I don't see a onDisconnect called on server side, as well as no events (timeouts, errors) that could help in detecting broken connection. The only approach at the moment is to write my own keep-alive logic, but that would be so cumbersome, not to mention changes in upper-level protocol.

Might be useful: https://stackoverflow.com/questions/29492995/lwip-stack-netconn-api-keep-connection-keep-alive

@stale
Copy link

stale bot commented Jun 2, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@copercini
Copy link
Contributor

copercini commented Jun 2, 2021

It's a bit hacky, but you can enable keepalive adding these lines

pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb
// Set the time between keepalive messages in milli-seconds
pcb->keep_idle = 45000; // 45 seconds
pcb->keep_intvl = 45000; // 45 seconds
pcb->keep_cnt = 7; //The number of unanswered probes required to force closure of the socket
// printf("keep alive is on"); //low level debug only

after here:

c->setNoDelay(_noDelay);

@stale
Copy link

stale bot commented Jun 2, 2021

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the stale label Jun 2, 2021
@positron96
Copy link
Author

@copercini big thanks, I'll try to make my own fork with this!

@stale
Copy link

stale bot commented Aug 2, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 2, 2021
@stale
Copy link

stale bot commented Aug 17, 2021

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants