mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-09 17:13:49 +08:00
Keepalive values can be configured at run time with LWIP_TCP_KEEPALIVE, but don't change this unless you know what you're doing (default are RFC1122 compliant). Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set in seconds.
Old TCP_KEEPALIVE can always be used, and its only difference with TCP_KEEPIDLE is this last use seconds and not milliseconds with setsockopt. Some documentation (not perfect, but...): http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.commtechref/doc/commtrf2/setsockopt.htm
This commit is contained in:
@@ -537,16 +537,24 @@ tcp_slowtmr(void)
|
||||
|
||||
/* Check if KEEPALIVE should be sent */
|
||||
if((pcb->so_options & SOF_KEEPALIVE) && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
|
||||
if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) {
|
||||
#if LWIP_TCP_KEEPALIVE
|
||||
if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + (pcb->keep_cnt*pcb->keep_intvl)) / TCP_SLOW_INTERVAL) {
|
||||
#else
|
||||
if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + TCP_MAXIDLE ) / TCP_SLOW_INTERVAL) {
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
|
||||
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + pcb->keep_cnt * TCP_KEEPINTVL) / TCP_SLOW_INTERVAL) {
|
||||
#if LWIP_TCP_KEEPALIVE
|
||||
else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + pcb->keep_cnt_sent * pcb->keep_intvl) / TCP_SLOW_INTERVAL) {
|
||||
#else
|
||||
else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT) / TCP_SLOW_INTERVAL) {
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
tcp_keepalive(pcb);
|
||||
pcb->keep_cnt++;
|
||||
pcb->keep_cnt_sent++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,8 +861,14 @@ tcp_alloc(u8_t prio)
|
||||
#endif /* LWIP_CALLBACK_API */
|
||||
|
||||
/* Init KEEPALIVE timer */
|
||||
pcb->keepalive = TCP_KEEPDEFAULT;
|
||||
pcb->keep_cnt = 0;
|
||||
pcb->keep_idle = TCP_KEEPIDLE_DEFAULT;
|
||||
|
||||
#if LWIP_TCP_KEEPALIVE
|
||||
pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT;
|
||||
pcb->keep_cnt = TCP_KEEPCNT_DEFAULT;
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
|
||||
pcb->keep_cnt_sent = 0;
|
||||
}
|
||||
return pcb;
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ tcp_process(struct tcp_pcb *pcb)
|
||||
|
||||
/* Update the PCB (in)activity timer. */
|
||||
pcb->tmr = tcp_ticks;
|
||||
pcb->keep_cnt = 0;
|
||||
pcb->keep_cnt_sent = 0;
|
||||
|
||||
/* Do different things depending on the TCP state. */
|
||||
switch (pcb->state) {
|
||||
@@ -825,7 +825,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
||||
pcb->sv += m;
|
||||
pcb->rto = (pcb->sa >> 3) + pcb->sv;
|
||||
|
||||
LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: RTO %"U16_F" (%"U16_F" miliseconds)\n",
|
||||
LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: RTO %"U16_F" (%"U16_F" milliseconds)\n",
|
||||
pcb->rto, pcb->rto * TCP_SLOW_INTERVAL));
|
||||
|
||||
pcb->rttest = 0;
|
||||
|
||||
@@ -683,7 +683,7 @@ tcp_keepalive(struct tcp_pcb *pcb)
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
|
||||
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt %"U16_F"\n", tcp_ticks, pcb->tmr, pcb->keep_cnt));
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n", tcp_ticks, pcb->tmr, pcb->keep_cnt_sent));
|
||||
|
||||
p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user