(closed) TCP socket error
Posted: Wed Oct 02, 2019 5:14 pm
Hi -
I'm trying to create a TCP server socket using LwIP calls. When I create/bind/listen on this socket, I will soon get an assertion failure:
don't call tcp_recved for listen-pcbs
From within LwIP. Here's the code (from lwip/lwip/src/core/tcp.c):
What's noteworthy is that I DON'T get this error if I set the socket to non-blocking:
My code is pretty vanilla; here are some snippets:
So...any ideas what's going on here? Is the socket callback somehow being invoked before my accept() call is finished? I'm not an experienced networking programmer, but I think at least I have the calls correct.
Thanks for looking.
I'm trying to create a TCP server socket using LwIP calls. When I create/bind/listen on this socket, I will soon get an assertion failure:
don't call tcp_recved for listen-pcbs
From within LwIP. Here's the code (from lwip/lwip/src/core/tcp.c):
(tcp_recved appears to be a default callback handler for when data is received on a socket.)void
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);
What's noteworthy is that I DON'T get this error if I set the socket to non-blocking:
Code: Select all
rc = fcntl(sock, F_SETFL, O_NONBLOCK);
Code: Select all
sock = socket(m_sockInfo[sockID].pAddrinfo->ai_family,
m_sockInfo[sockID].pAddrinfo->ai_socktype,
m_sockInfo[sockID].pAddrinfo->ai_protocol);
rc = bind(sock, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
if (rc == 0)
{
ESP_LOGI(TAG, "socketConnect(): socket %s bind() successful.", SOCK_ID_TEXT[sockID].c_str());
// if the protocol is SOCK_DGRAM, we're done; if SOCK_STREAM, we need to listen.
if (protocol == SOCK_STREAM)
{
rc = listen(sock, 10);
if (rc == 0)
{
ESP_LOGI(TAG, "socketConnect(): socket %s listen() successful.", SOCK_ID_TEXT[sockID].c_str());
}
}
}
Thanks for looking.