diff --git a/examples/test-LwIP-netconn/scpi_server.c b/examples/test-LwIP-netconn/scpi_server.c index 2018bcd1..61472353 100644 --- a/examples/test-LwIP-netconn/scpi_server.c +++ b/examples/test-LwIP-netconn/scpi_server.c @@ -246,6 +246,10 @@ static int processIoListen(scpi_t * context, user_data_t * user_data) { } else { /* connection established */ SCPI_Event_DeviceConnected(context, newconn); + ip_set_option(newconn->pcb.tcp, SOF_KEEPALIVE); + newconn->pcb.tcp->keep_idle = SCPI_KEEP_IDLE; // Override TCP_KEEPIDLE_DEFAULT for this connection. + newconn->pcb.tcp->keep_intvl = SCPI_KEEP_INTVL; // Override TCP_KEEPINTVL_DEFAULT for this connection. + newconn->pcb.tcp->keep_cnt = SCPI_KEEP_CNT; // Override TCP_KEEPCNT_DEFAULT for this connection. user_data->io = newconn; } } @@ -263,6 +267,10 @@ static int processSrqIoListen(scpi_t * context, user_data_t * user_data) { } else { /* control connection established */ SCPI_Event_ControlConnected(context, newconn); + ip_set_option(newconn->pcb.tcp, SOF_KEEPALIVE); + newconn->pcb.tcp->keep_idle = SCPI_KEEP_IDLE; // Override TCP_KEEPIDLE_DEFAULT for this connection. + newconn->pcb.tcp->keep_intvl = SCPI_KEEP_INTVL; // Override TCP_KEEPINTVL_DEFAULT for this connection. + newconn->pcb.tcp->keep_cnt = SCPI_KEEP_CNT; // Override TCP_KEEPCNT_DEFAULT for this connection. user_data->control_io = newconn; } } diff --git a/examples/test-LwIP-netconn/scpi_server.h b/examples/test-LwIP-netconn/scpi_server.h index 90bdc649..dedc1583 100644 --- a/examples/test-LwIP-netconn/scpi_server.h +++ b/examples/test-LwIP-netconn/scpi_server.h @@ -32,6 +32,10 @@ extern "C" { #endif +#define SCPI_KEEP_IDLE 2000 // (ms) keepalive quiet time after last TCP packet +#define SCPI_KEEP_INTVL 1000 // (ms) keepalive repeat interval +#define SCPI_KEEP_CNT 4 // Retry count before terminating connection (SCPI_KEEP_INTVL * SCPI_KEEP_INTVL (ms)). + #define SCPI_DEVICE_PORT 5025 // scpi-raw standard port #define SCPI_CONTROL_PORT 5026 // libscpi control port (not part of the standard)