Arm Mbed OS support forum

Ping function to help overcome long connect timeout

I hit a snag trying to connect to local IP that was down.
The problem is the timeout defaults to 30 seconds and I need 100ms maximum.
Bare in mind the average successful transaction time of a 64 byte packet is 2-3ms, I didn’t want to wait to find out there’s nothing hanging on the end of an IP.

However the resolve from the Mbed guys was minor adjust in the LWIPStack.cpp file (around line 350)

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

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

This now enables the timeout for the connect function.
I’m successfully using a 100ms connect timeout in one project and no hard fault when the remote IP drops in and out.

The general consensus is not to change this because timeout is not normally enabled in the connect function?
Can’'t think why, and who would wait 30 seconds to find out the remote IP is down.

My question is if we had a ‘ping’ function in Mbed we could check for a dead IP before a connect attempt and also get some reply times that could help with more dynamic timing within the program.
Then just leave the timeout disabled for the connect function.

I’m far from expert in IOT so does anyone else think a ‘ping’ function would be helpful or if the connect function should have the timeout enabled?

2 Likes