diff --git a/src/core/tcp.c b/src/core/tcp.c index 55902600..7fd36865 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -576,6 +576,9 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) { int wnd_inflation; + /* pcb->state LISTEN not allowed here */ + LWIP_ASSERT("don't call tcp_recved for listen-pcbs", + pcb->state != LISTEN); LWIP_ASSERT("tcp_recved: len would wrap rcv_wnd\n", len <= 0xffff - pcb->rcv_wnd ); @@ -1275,7 +1278,9 @@ tcp_new(void) */ void tcp_arg(struct tcp_pcb *pcb, void *arg) -{ +{ + /* This function is allowed to be called for both listen pcbs and + connection pcbs. */ pcb->callback_arg = arg; } #if LWIP_CALLBACK_API @@ -1290,6 +1295,7 @@ tcp_arg(struct tcp_pcb *pcb, void *arg) void tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv) { + LWIP_ASSERT("invalid socket state for recv callback", pcb->state != LISTEN); pcb->recv = recv; } @@ -1303,6 +1309,7 @@ tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv) void tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) { + LWIP_ASSERT("invalid socket state for sent callback", pcb->state != LISTEN); pcb->sent = sent; } @@ -1317,6 +1324,7 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) void tcp_err(struct tcp_pcb *pcb, tcp_err_fn err) { + LWIP_ASSERT("invalid socket state for err callback", pcb->state != LISTEN); pcb->errf = err; } @@ -1331,6 +1339,8 @@ tcp_err(struct tcp_pcb *pcb, tcp_err_fn err) void tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) { + /* This function is allowed to be called for both listen pcbs and + connection pcbs. */ pcb->accept = accept; } #endif /* LWIP_CALLBACK_API */ @@ -1345,6 +1355,7 @@ tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) void tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval) { + LWIP_ASSERT("invalid socket state for poll", pcb->state != LISTEN); #if LWIP_CALLBACK_API pcb->poll = poll; #else /* LWIP_CALLBACK_API */ diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index cf4ff76a..a32d0258 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -898,6 +898,10 @@ tcp_output(struct tcp_pcb *pcb) s16_t i = 0; #endif /* TCP_CWND_DEBUG */ + /* pcb->state LISTEN not allowed here */ + LWIP_ASSERT("don't call tcp_output for listen-pcbs", + pcb->state != LISTEN); + /* First, check if we are invoked by the TCP input processing code. If so, we do not output anything. Instead, we rely on the input processing code to call us when input processing is done