-
Notifications
You must be signed in to change notification settings - Fork 13.3k
TCP keepalive(2h,75s,9) API + status helper + change/disable methods (not enabled by default) #3937
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ class ClientContext | |
tcp_sent(pcb, &_s_sent); | ||
tcp_err(pcb, &_s_error); | ||
tcp_poll(pcb, &_s_poll, 1); | ||
|
||
// not enabled by default for 2.4.0 | ||
//keepAlive(); | ||
} | ||
|
||
err_t abort() | ||
|
@@ -341,6 +344,38 @@ class ClientContext | |
return _write_from_source(new BufferedStreamDataSource<ProgmemStream>(stream, size)); | ||
} | ||
|
||
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT) | ||
{ | ||
if (idle_sec && intv_sec && count) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if any 2 of the 3 values are non-zero? Are all combinations allowed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (mostly thinking of sanity checks, if necessary) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any 0 is an invalid value for keep-alive api, so any 0 disables keep-alive. |
||
_pcb->so_options |= SOF_KEEPALIVE; | ||
_pcb->keep_idle = (uint32_t)1000 * idle_sec; | ||
_pcb->keep_intvl = (uint32_t)1000 * intv_sec; | ||
_pcb->keep_cnt = count; | ||
} | ||
else | ||
_pcb->so_options &= ~SOF_KEEPALIVE; | ||
} | ||
|
||
bool isKeepAliveEnabled () const | ||
{ | ||
return !!(_pcb->so_options & SOF_KEEPALIVE); | ||
} | ||
|
||
uint16_t getKeepAliveIdle () const | ||
{ | ||
return isKeepAliveEnabled()? (_pcb->keep_idle + 500) / 1000: 0; | ||
} | ||
|
||
uint16_t getKeepAliveInterval () const | ||
{ | ||
return isKeepAliveEnabled()? (_pcb->keep_intvl + 500) / 1000: 0; | ||
} | ||
|
||
uint8_t getKeepAliveCount () const | ||
{ | ||
return isKeepAliveEnabled()? _pcb->keep_cnt: 0; | ||
} | ||
|
||
protected: | ||
|
||
bool _is_timeout() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do #defines count against available heap, or is it better to make these static const and put them in flash?
(I'm thinking of the free heap project, every byte counts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unlike
static const
,#define
count for nothing in ram nor flash.