From 81ce32efc7ddebf1f09851d4e4ac34681f436e57 Mon Sep 17 00:00:00 2001 From: helge <helgewurst@web.de> Date: 周六, 06 11月 2021 22:00:24 +0800 Subject: [PATCH] set keep-alive defaults for new connections --- examples/test-LwIP-netconn/scpi_server.c | 8 ++++++++ examples/test-LwIP-netconn/scpi_server.h | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/examples/test-LwIP-netconn/scpi_server.c b/examples/test-LwIP-netconn/scpi_server.c index 309dd38..9252ba5 100644 --- a/examples/test-LwIP-netconn/scpi_server.c +++ b/examples/test-LwIP-netconn/scpi_server.c @@ -253,6 +253,10 @@ } else { /* connection established */ iprintf("***Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); + newconn->pcb.tcp->so_options |= 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; } } @@ -270,6 +274,10 @@ } else { /* control connection established */ iprintf("***Control Connection established %s\r\n", inet_ntoa(newconn->pcb.ip->remote_ip)); + newconn->pcb.tcp->so_options |= 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 4d2895f..b9900ef 100644 --- a/examples/test-LwIP-netconn/scpi_server.h +++ b/examples/test-LwIP-netconn/scpi_server.h @@ -29,6 +29,9 @@ #ifndef _SCPI_SERVER_H_ #define _SCPI_SERVER_H_ +#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)). #include <stdint.h> -- Gitblit v1.9.1