Let FIN come through although TF_RXCLOSED is set, send RST when data is received although TF_RXCLOSED is set, added TCP_EVENT_CLOSED for clearer code

This commit is contained in:
goldsimon 2010-05-15 18:12:37 +00:00
parent 874d1641df
commit a880709776
2 changed files with 27 additions and 10 deletions

View File

@ -346,6 +346,12 @@ tcp_input(struct pbuf *p, struct netif *inp)
} }
if (recv_data != NULL) { if (recv_data != NULL) {
if (pcb->flags & TF_RXCLOSED) {
/* received data although already closed -> abort (send RST) to
notify the remote host that not all data has been processed */
tcp_abort(pcb);
goto aborted;
}
if (flags & TCP_PSH) { if (flags & TCP_PSH) {
recv_data->flags |= PBUF_FLAG_PUSH; recv_data->flags |= PBUF_FLAG_PUSH;
} }
@ -371,7 +377,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
if (pcb->rcv_wnd != TCP_WND) { if (pcb->rcv_wnd != TCP_WND) {
pcb->rcv_wnd++; pcb->rcv_wnd++;
} }
TCP_EVENT_RECV(pcb, NULL, ERR_OK, err); TCP_EVENT_CLOSED(pcb, err);
if (err == ERR_ABRT) { if (err == ERR_ABRT) {
goto aborted; goto aborted;
} }
@ -391,7 +397,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
Below this line, 'pcb' may not be dereferenced! */ Below this line, 'pcb' may not be dereferenced! */
aborted: aborted:
tcp_input_pcb = NULL; tcp_input_pcb = NULL;
recv_data = NULL;
/* give up our reference to inseg.p */ /* give up our reference to inseg.p */
if (inseg.p != NULL) if (inseg.p != NULL)

View File

@ -199,6 +199,8 @@ PACK_STRUCT_END
LWIP_EVENT_SENT, NULL, space, ERR_OK) LWIP_EVENT_SENT, NULL, space, ERR_OK)
#define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
LWIP_EVENT_RECV, (p), 0, (err)) LWIP_EVENT_RECV, (p), 0, (err))
#define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
LWIP_EVENT_RECV, NULL, 0, ERR_OK)
#define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
LWIP_EVENT_CONNECTED, NULL, 0, (err)) LWIP_EVENT_CONNECTED, NULL, 0, (err))
#define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
@ -224,13 +226,22 @@ PACK_STRUCT_END
#define TCP_EVENT_RECV(pcb,p,err,ret) \ #define TCP_EVENT_RECV(pcb,p,err,ret) \
do { \ do { \
if(((pcb)->recv != NULL) && (!((pcb)->flags & TF_RXCLOSED))) { \ if((pcb)->recv != NULL) { \
(ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\ (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
} else { \ } else { \
(ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \ (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
} \ } \
} while (0) } while (0)
#define TCP_EVENT_CLOSED(pcb,ret) \
do { \
if(((pcb)->recv != NULL)) { \
(ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
} else { \
(ret) = ERR_OK; \
} \
} while (0)
#define TCP_EVENT_CONNECTED(pcb,err,ret) \ #define TCP_EVENT_CONNECTED(pcb,err,ret) \
do { \ do { \
if((pcb)->connected != NULL) \ if((pcb)->connected != NULL) \