6 years, 8 months ago.

Enabling TCP Keepalive and other socket options

Hi all,

I'm working on an application that needs TCP socket keepalive functionality. I'm having trouble configuring lwip to enable this functionality, if it is even available. I'm using an STM Nucleo F429ZI dev board and Mbed 5.7.

From what I've been able to piece together from the lwip headers and a bunch of googling, by default, the get/setsockopt() methods can't be used. This seems to be in line with what's happening, as the get/setsockopt() methods return either NSAPI_ERROR_UNSUPPORTED (-3002) or NSAPI_ERROR_PARAMETER (-3003), depending on the function I'm calling. It seems like I need to define LWIP_SOCKET (see here: https://github.com/ARMmbed/mbed-os/blob/91e6db1ea251ffcc973001ed90477f42fdca5751/features/FEATURE_LWIP/lwip-interface/lwip/src/include/lwip/sockets.h#L44) in order for this to be enabled, and I have done that in my mbed_app.json file. I can confirm that after the build, my mbed_config.h file DOES define LWIP_SOCKET, but I still get -3002/-3003 errors. From there, I basically just added a bunch more macros like LWIP_TCP_KEEPALIVE (http://lwip.wikia.com/wiki/Raw/TCP), and tried to figure out how to use the BSD socket API (https://stackoverflow.com/a/29580393/3684433), but nothing has worked so far. I can't tell if I'm misusing mbed's configuration files or if I'm on the wrong track altogether. I've copied my mbed_app.json at the end of this post... for some reason the "insert images or files" button doesn't work.

If you have some experience with configuration of lwip features, I would appreciate your insight. Thanks!

{ "target_overrides": { "NUCLEO_F429ZI": { "target.device_has_add": ["SERIAL_ASYNCH"], "target.features_add" : ["COMMON_PAL", "LWIP"], "mbed-trace.enable": 1, "eth-enabled": 1, "bsd-sockets": 1, "tcp-keepalive": 1, "tcp-keepidle": 5000, "tcp-keepintvl": 2000, "tcp-keepcnt": 3 } },

"config": { "eth-enabled": { "help": "Enable lwip ethernet", "value": 1, "macro_name": "LWIP_ETHERNET_ENABLED" }, "bsd-sockets": { "help": "Enable standard socket API", "value": 1, "macro_name": "LWIP_SOCKET" }, "tcp-keepalive": { "help": "Enable TCP keepalive", "value": 1, "macro_name": "LWIP_TCP_KEEPALIVE" }, "tcp-keepidle": { "help": "TCP keepalive idle default (ms)", "value": 5000, "macro_name": "TCP_KEEPIDLE_DEFAULT" }, "tcp-keepintvl": { "help": "TCP keepalive interval default (ms)", "value": 2000, "macro_name": "TCP_KEEPINTVL_DEFAULT" }, "tcp-keepcnt": { "help": "TCP keepalive count default", "value": 3, "macro_name": "TCP_KEEPCNT_DEFAULT" } } }

Be the first to answer this question.