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

Add option to configure TCP keepalives #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,18 @@ bool AsyncClient::getNoDelay(){
return tcp_nagle_disabled(_pcb);
}

void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt){
if(ms!=0) {
_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 = ms;
_pcb->keep_intvl = ms;
_pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket
} else {
_pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb
}
}

uint16_t AsyncClient::getMss(){
if(!_pcb) {
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/AsyncTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class AsyncClient {
void setNoDelay(bool nodelay);
bool getNoDelay();

void setKeepAlive(uint32_t ms, uint8_t cnt);

uint32_t getRemoteAddress();
uint16_t getRemotePort();
uint32_t getLocalAddress();
Expand Down