Arm Mbed OS support forum

Set LWIP TCP connect timeout option?

Does anyone know if there is an option to set LWIP TCP connect timeout in one of the many json files?
I think the default is 30 seconds but that is way too long for most local network applications.

I could change some settings in OS 5.15 a while ago by doing the change below in the LWPStack.cpp file and then set it to 200 to 300 mS which is ideal.

Fortunately I can still do this with OS 6.15.1 but its a pain to have to change this every time I update OS.

    LWPStack.cpp file around line 350

    netconn_set_nonblocking(s->conn, false);
    err_t err = netconn_connect(s->conn, &ip_addr, address.get_port());
    netconn_set_nonblocking(s->conn, true);

    to...

    netconn_set_nonblocking(s->conn, true);
    err_t err = netconn_connect(s->conn, &ip_addr, address.get_port());

Hello Paul,

As described in mbed-os/connectivity/lwipstack/mbed_lib.json the following timeout’s can be configured for the lwipstack via a mbed_app.json:

        "dhcp-timeout": {
            "help": "DHCP timeout value",
            "value": 60
        },
        ...
        "tcp-close-timeout": {
            "help": "Maximum timeout (ms) for TCP close handshaking timeout",
            "value": 1000
        },

I have never tried to use it but the first one could be the one you are looking for:
mbed_app.json:

{
    "target_overrides": {
        "*": {
            "lwip.dhcp-timeout": 1
        }
    }
}

Or perhaps the following works too.

{
    "target_overrides": {
        "*": {
            "lwip.dhcp-timeout": 0.3
        }
    }
}

Hello Zoltan,
Nice to hear from you!

Unfortunately no that doesn’t work, I think its tied in with blocking/non-blocking.
That gives me the same result as:

remote_device.set_timeout(200); 200ms timeout.

But I have to set that netconn_set_nonblocking to true first as below.

nsapi_error_t LWIP::socket_connect(nsapi_socket_t handle, const SocketAddress &address)
{
    struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)handle;
    ip_addr_t ip_addr;

    nsapi_addr_t addr = address.get_addr();
    if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
        return NSAPI_ERROR_PARAMETER;
    }

    netconn_set_nonblocking(s->conn, true);
    err_t err = netconn_connect(s->conn, &ip_addr, address.get_port());
/*
    netconn_set_nonblocking(s->conn, false);
    err_t err = netconn_connect(s->conn, &ip_addr, address.get_port());
    netconn_set_nonblocking(s->conn, true);
*/
    return err_remap(err);
}

I did try again remote_device.set_blocking(false); but that does nothing for the connect timeout.

No worries, I have the work-a-around that fortunately has not been broken throughout all the mbed updates.

I can’t understand why no one else has had this issue, a 30 second blocking all other processes function makes no sense on a runtime operating system, unless I’m not using it correctly which is a high probability. I did question this with the mbed team a couple of years ago and was told it would require a lot of changes to implement and would not be backwardly compatible with other users programs, something that does not normally stop mbed changing things.