(closed) TCP socket error

User avatar
Posts: 384
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(closed) TCP socket error

Postby mzimmers » 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):
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);
(tcp_recved appears to be a default callback handler for when data is received on a socket.)

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);
My code is pretty vanilla; here are some snippets:

Code: Select all

    sock = socket(m_sockInfo[sockID].pAddrinfo->ai_family,
        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());
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.

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 27 guests