Skip to content

[HELP] select() never returns a positive value when listening to a TCP socket on SoftAP (ESP32-C6) #16044

Closed
@engdavidiogo

Description

@engdavidiogo

Description

Summary
I'm developing a simple HTTP server that listens for TCP connections on the wlan1 interface (SoftAP mode).
The main loop uses select() with a timeout to wait for incoming connections. However, even when a client is connected and sending valid HTTP requests, the select() function never returns a positive value, which prevents accept() from being called.

The Problem

  • The TCP socket is properly configured using socket(), bind(), and listen(), associated with the IP address of the SoftAP interface (wlan1).
  • The main loop uses select() with a 1-second timeout to wait for activity.
  • Even when a client is connected and sends an HTTP request, select() always returns 0 (timeout).
  • As a result, FD_ISSET(server_sock, &read_fds) is never true.
  • This prevents accept() from being called, making the HTTP server completely inaccessible, even with active network traffic.

Expected behavior

  • A client connects to the SoftAP (wlan1).
  • The client sends a valid HTTP request (e.g., GET /state).
  • server_sock should be marked as readable.
  • select() should return 1.
  • FD_ISSET(server_sock, &read_fds) should be true.
  • accept() should be called and the client handled.

Current Behavior

  • select() always returns 0 (timeout), even when the client is actively connected and sending requests.
  • FD_ISSET(server_sock, &read_fds) is never true.
  • accept() is never called.
  • The server remains "active", but is completely unresponsive.

Socket Configuration Example

server_sock = socket(AF_INET, SOCK_STREAM, 0);

netlib_get_ipv4addr("wlan1", &softap_ip);

server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(80);
server_addr.sin_addr = softap_ip;

bind(server_sock, (struct sockaddr *)&server_addr, sizeof(server_addr));
listen(server_sock, 5);

Main Loop with select()

while (webserver_running)
{
    fd_set read_fds;
    struct timeval timeout;

    FD_ZERO(&read_fds);
    FD_SET(server_sock, &read_fds);

    timeout.tv_sec = 1;
    timeout.tv_usec = 0;

    int sel_ret = select(server_sock + 1, &read_fds, NULL, NULL, &timeout);

    if (sel_ret < 0)
    {
        break; // select() failed
    }
    else if (sel_ret == 0)
    {
        continue; // Timeout, no activity
    }

    if (FD_ISSET(server_sock, &read_fds))
    {
        int client_sock = accept(server_sock, ...);
        if (client_sock >= 0)
        {
            handle_client(client_sock);
        }
    }
}

Questions

  1. Is this behavior expected when using NuttX sockets in SoftAP mode?

  2. Is there any known limitation with select() or socket monitoring on the wlan1 interface?

  3. Is the way I'm using select() appropriate in this context? Am I missing something important?

  4. Could it be that the current implementation of select() is not correctly monitoring SOCK_STREAM sockets on the SoftAP (wlan1) interface?

I would be grateful for any analysis or guidance!

Platform
Board: ESP32-C6 (ESP32C6-DevKitC)

Verification

  • I have verified before submitting the report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions