mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-11 10:13:48 +00:00
- moved processing of refused_data to an own function (used from tcp_fasttmr and tcp_input);
- improved readability of tcp_slowtmr by using defines to access keepalive variables
This commit is contained in:
parent
78f0307246
commit
0fb07ba328
@ -66,6 +66,14 @@
|
|||||||
#define TCP_ENSURE_LOCAL_PORT_RANGE(port) (((port) & ~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START)
|
#define TCP_ENSURE_LOCAL_PORT_RANGE(port) (((port) & ~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LWIP_TCP_KEEPALIVE
|
||||||
|
#define TCP_KEEP_DUR(pcb) ((pcb)->keep_cnt * (pcb)->keep_intvl)
|
||||||
|
#define TCP_KEEP_INTVL(pcb) ((pcb)->keep_intvl)
|
||||||
|
#else /* LWIP_TCP_KEEPALIVE */
|
||||||
|
#define TCP_KEEP_DUR(pcb) TCP_MAXIDLE
|
||||||
|
#define TCP_KEEP_INTVL(pcb) TCP_KEEPINTVL_DEFAULT
|
||||||
|
#endif /* LWIP_TCP_KEEPALIVE */
|
||||||
|
|
||||||
const char * const tcp_state_str[] = {
|
const char * const tcp_state_str[] = {
|
||||||
"CLOSED",
|
"CLOSED",
|
||||||
"LISTEN",
|
"LISTEN",
|
||||||
@ -849,8 +857,9 @@ tcp_slowtmr(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Increase the retransmission timer if it is running */
|
/* Increase the retransmission timer if it is running */
|
||||||
if(pcb->rtime >= 0)
|
if(pcb->rtime >= 0) {
|
||||||
++pcb->rtime;
|
++pcb->rtime;
|
||||||
|
}
|
||||||
|
|
||||||
if (pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
|
if (pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
|
||||||
/* Time for a retransmission. */
|
/* Time for a retransmission. */
|
||||||
@ -897,14 +906,8 @@ tcp_slowtmr(void)
|
|||||||
if((pcb->so_options & SOF_KEEPALIVE) &&
|
if((pcb->so_options & SOF_KEEPALIVE) &&
|
||||||
((pcb->state == ESTABLISHED) ||
|
((pcb->state == ESTABLISHED) ||
|
||||||
(pcb->state == CLOSE_WAIT))) {
|
(pcb->state == CLOSE_WAIT))) {
|
||||||
#if LWIP_TCP_KEEPALIVE
|
|
||||||
if((u32_t)(tcp_ticks - pcb->tmr) >
|
if((u32_t)(tcp_ticks - pcb->tmr) >
|
||||||
(pcb->keep_idle + (pcb->keep_cnt*pcb->keep_intvl))
|
(pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL)
|
||||||
/ 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 "));
|
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to "));
|
||||||
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
|
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
|
||||||
@ -913,15 +916,9 @@ tcp_slowtmr(void)
|
|||||||
++pcb_remove;
|
++pcb_remove;
|
||||||
++pcb_reset;
|
++pcb_reset;
|
||||||
}
|
}
|
||||||
#if LWIP_TCP_KEEPALIVE
|
|
||||||
else if((u32_t)(tcp_ticks - pcb->tmr) >
|
else if((u32_t)(tcp_ticks - pcb->tmr) >
|
||||||
(pcb->keep_idle + pcb->keep_cnt_sent * pcb->keep_intvl)
|
(pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEP_INTVL(pcb))
|
||||||
/ TCP_SLOW_INTERVAL)
|
/ 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);
|
tcp_keepalive(pcb);
|
||||||
pcb->keep_cnt_sent++;
|
pcb->keep_cnt_sent++;
|
||||||
@ -1052,34 +1049,8 @@ tcp_fasttmr(void)
|
|||||||
struct tcp_pcb *next = pcb->next;
|
struct tcp_pcb *next = pcb->next;
|
||||||
/* If there is data which was previously "refused" by upper layer */
|
/* If there is data which was previously "refused" by upper layer */
|
||||||
if (pcb->refused_data != NULL) {
|
if (pcb->refused_data != NULL) {
|
||||||
/* Notify again application with data previously received. */
|
if (tcp_process_refused_data(pcb) == ERR_ABRT) {
|
||||||
err_t err;
|
|
||||||
u8_t refused_flags = pcb->refused_data->flags;
|
|
||||||
/* set pcb->refused_data to NULL in case the callback frees it and then
|
|
||||||
closes the pcb */
|
|
||||||
struct pbuf *refused_data = pcb->refused_data;
|
|
||||||
pcb->refused_data = NULL;
|
|
||||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_fasttmr: notify kept packet\n"));
|
|
||||||
TCP_EVENT_RECV(pcb, refused_data, ERR_OK, err);
|
|
||||||
if (err == ERR_OK) {
|
|
||||||
/* did refused_data include a FIN? If so, handle it now. */
|
|
||||||
if (refused_flags & PBUF_FLAG_TCP_FIN) {
|
|
||||||
/* correct rcv_wnd as the application won't call tcp_recved()
|
|
||||||
for the FIN's seqno */
|
|
||||||
if (pcb->rcv_wnd != TCP_WND) {
|
|
||||||
pcb->rcv_wnd++;
|
|
||||||
}
|
|
||||||
TCP_EVENT_CLOSED(pcb, err);
|
|
||||||
if (err == ERR_ABRT) {
|
|
||||||
pcb = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (err == ERR_ABRT) {
|
|
||||||
/* if err == ERR_ABRT, 'pcb' is already deallocated */
|
|
||||||
pcb = NULL;
|
pcb = NULL;
|
||||||
} else {
|
|
||||||
/* data is still refused */
|
|
||||||
pcb->refused_data = refused_data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,6 +1066,45 @@ tcp_fasttmr(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Pass pcb->refused_data to the recv callback */
|
||||||
|
err_t
|
||||||
|
tcp_process_refused_data(struct tcp_pcb *pcb)
|
||||||
|
{
|
||||||
|
err_t err;
|
||||||
|
u8_t refused_flags = pcb->refused_data->flags;
|
||||||
|
/* set pcb->refused_data to NULL in case the callback frees it and then
|
||||||
|
closes the pcb */
|
||||||
|
struct pbuf *refused_data = pcb->refused_data;
|
||||||
|
pcb->refused_data = NULL;
|
||||||
|
/* Notify again application with data previously received. */
|
||||||
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: notify kept packet\n"));
|
||||||
|
TCP_EVENT_RECV(pcb, refused_data, ERR_OK, err);
|
||||||
|
if (err == ERR_OK) {
|
||||||
|
/* did refused_data include a FIN? */
|
||||||
|
if (refused_flags & PBUF_FLAG_TCP_FIN) {
|
||||||
|
/* correct rcv_wnd as the application won't call tcp_recved()
|
||||||
|
for the FIN's seqno */
|
||||||
|
if (pcb->rcv_wnd != TCP_WND) {
|
||||||
|
pcb->rcv_wnd++;
|
||||||
|
}
|
||||||
|
TCP_EVENT_CLOSED(pcb, err);
|
||||||
|
if (err == ERR_ABRT) {
|
||||||
|
return ERR_ABRT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (err == ERR_ABRT) {
|
||||||
|
/* if err == ERR_ABRT, 'pcb' is already deallocated */
|
||||||
|
/* Drop incoming packets because pcb is "full" (only if the incoming
|
||||||
|
segment contains data). */
|
||||||
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: drop incoming packets, because pcb is \"full\"\n"));
|
||||||
|
return ERR_ABRT;
|
||||||
|
} else {
|
||||||
|
/* data is still refused, pbuf is still valid (go on for ACK-only packets) */
|
||||||
|
pcb->refused_data = refused_data;
|
||||||
|
}
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deallocates a list of TCP segments (tcp_seg structures).
|
* Deallocates a list of TCP segments (tcp_seg structures).
|
||||||
*
|
*
|
||||||
|
@ -306,36 +306,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
|||||||
|
|
||||||
/* If there is data which was previously "refused" by upper layer */
|
/* If there is data which was previously "refused" by upper layer */
|
||||||
if (pcb->refused_data != NULL) {
|
if (pcb->refused_data != NULL) {
|
||||||
u8_t refused_flags = pcb->refused_data->flags;
|
if ((tcp_process_refused_data(pcb) == ERR_ABRT) ||
|
||||||
/* set pcb->refused_data to NULL in case the callback frees it and then
|
((pcb->refused_data != NULL) && (tcplen > 0))) {
|
||||||
closes the pcb */
|
/* pcb has been aborted or refused data is still refused and the new
|
||||||
struct pbuf *refused_data = pcb->refused_data;
|
segment contains data */
|
||||||
pcb->refused_data = NULL;
|
TCP_STATS_INC(tcp.drop);
|
||||||
/* Notify again application with data previously received. */
|
snmp_inc_tcpinerrs();
|
||||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: notify kept packet\n"));
|
goto aborted;
|
||||||
TCP_EVENT_RECV(pcb, refused_data, ERR_OK, err);
|
|
||||||
if (err == ERR_OK) {
|
|
||||||
/* did refused_data include a FIN? */
|
|
||||||
if (refused_flags & PBUF_FLAG_TCP_FIN) {
|
|
||||||
/* correct rcv_wnd as the application won't call tcp_recved()
|
|
||||||
for the FIN's seqno */
|
|
||||||
if (pcb->rcv_wnd != TCP_WND) {
|
|
||||||
pcb->rcv_wnd++;
|
|
||||||
}
|
|
||||||
TCP_EVENT_CLOSED(pcb, err);
|
|
||||||
if (err == ERR_ABRT) {
|
|
||||||
goto dropped;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((err == ERR_ABRT) || (tcplen > 0)) {
|
|
||||||
/* if err == ERR_ABRT, 'pcb' is already deallocated */
|
|
||||||
/* Drop incoming packets because pcb is "full" (only if the incoming
|
|
||||||
segment contains data). */
|
|
||||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: drop incoming packets, because pcb is \"full\"\n"));
|
|
||||||
goto dropped;
|
|
||||||
} else {
|
|
||||||
/* data is still refused, pbuf is still valid (go on for ACK-only packets) */
|
|
||||||
pcb->refused_data = refused_data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcp_input_pcb = pcb;
|
tcp_input_pcb = pcb;
|
||||||
|
@ -72,6 +72,7 @@ void tcp_rexmit (struct tcp_pcb *pcb);
|
|||||||
void tcp_rexmit_rto (struct tcp_pcb *pcb);
|
void tcp_rexmit_rto (struct tcp_pcb *pcb);
|
||||||
void tcp_rexmit_fast (struct tcp_pcb *pcb);
|
void tcp_rexmit_fast (struct tcp_pcb *pcb);
|
||||||
u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
|
u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
|
||||||
|
err_t tcp_process_refused_data(struct tcp_pcb *pcb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the Nagle algorithm: try to combine user data to send as few TCP
|
* This is the Nagle algorithm: try to combine user data to send as few TCP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user