altcp: support for setting keepalive parameters

(cherry picked from commit b04d8a6a6c)
This commit is contained in:
David Girault 2018-08-28 16:23:20 +02:00 committed by Simon Goldschmidt
parent 5cea646b12
commit a9a215c52e
5 changed files with 88 additions and 0 deletions

View File

@ -1256,6 +1256,10 @@ const struct altcp_functions altcp_mbedtls_functions = {
altcp_default_get_tcp_addrinfo, altcp_default_get_tcp_addrinfo,
altcp_default_get_ip, altcp_default_get_ip,
altcp_default_get_port altcp_default_get_port
#if LWIP_TCP_KEEPALIVE
, altcp_default_keepalive_disable
, altcp_default_keepalive_enable
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
, altcp_default_dbg_get_tcp_state , altcp_default_dbg_get_tcp_state
#endif #endif

View File

@ -501,6 +501,24 @@ altcp_get_port(struct altcp_pcb *conn, int local)
return 0; return 0;
} }
#if LWIP_TCP_KEEPALIVE
void
altcp_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->fns && conn->fns->keepalive_disable) {
conn->fns->keepalive_disable(conn);
}
}
void
altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count)
{
if (conn && conn->fns && conn->fns->keepalive_enable) {
conn->fns->keepalive_enable(conn, idle, intvl, count);
}
}
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
enum tcp_state enum tcp_state
altcp_dbg_get_tcp_state(struct altcp_pcb *conn) altcp_dbg_get_tcp_state(struct altcp_pcb *conn)
@ -666,6 +684,24 @@ altcp_default_get_port(struct altcp_pcb *conn, int local)
return 0; return 0;
} }
#if LWIP_TCP_KEEPALIVE
void
altcp_default_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->inner_conn) {
altcp_keepalive_disable(conn->inner_conn);
}
}
void
altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count)
{
if (conn && conn->inner_conn) {
altcp_keepalive_enable(conn->inner_conn, idle, intvl, count);
}
}
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
enum tcp_state enum tcp_state
altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn) altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn)

View File

@ -49,6 +49,7 @@
#include "lwip/altcp_tcp.h" #include "lwip/altcp_tcp.h"
#include "lwip/priv/altcp_priv.h" #include "lwip/priv/altcp_priv.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include <string.h> #include <string.h>
@ -446,6 +447,31 @@ altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio)
} }
} }
#if LWIP_TCP_KEEPALIVE
static void
altcp_tcp_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->state) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
ALTCP_TCP_ASSERT_CONN(conn);
ip_reset_option(pcb, SOF_KEEPALIVE);
}
}
static void
altcp_tcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t cnt)
{
if (conn && conn->state) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
ALTCP_TCP_ASSERT_CONN(conn);
ip_set_option(pcb, SOF_KEEPALIVE);
pcb->keep_idle = idle ? idle : TCP_KEEPIDLE_DEFAULT;
pcb->keep_intvl = intvl ? intvl : TCP_KEEPINTVL_DEFAULT;
pcb->keep_cnt = cnt ? cnt : TCP_KEEPCNT_DEFAULT;
}
}
#endif
static void static void
altcp_tcp_dealloc(struct altcp_pcb *conn) altcp_tcp_dealloc(struct altcp_pcb *conn)
{ {
@ -535,6 +561,10 @@ const struct altcp_functions altcp_tcp_functions = {
altcp_tcp_get_tcp_addrinfo, altcp_tcp_get_tcp_addrinfo,
altcp_tcp_get_ip, altcp_tcp_get_ip,
altcp_tcp_get_port altcp_tcp_get_port
#if LWIP_TCP_KEEPALIVE
, altcp_tcp_keepalive_disable
, altcp_tcp_keepalive_enable
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
, altcp_tcp_dbg_get_tcp_state , altcp_tcp_dbg_get_tcp_state
#endif #endif

View File

@ -129,6 +129,11 @@ err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr,
ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local); ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local);
u16_t altcp_get_port(struct altcp_pcb *conn, int local); u16_t altcp_get_port(struct altcp_pcb *conn, int local);
#if LWIP_TCP_KEEPALIVE
void altcp_keepalive_disable(struct altcp_pcb *conn);
void altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count);
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn); enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn);
#endif #endif

View File

@ -85,6 +85,11 @@ typedef err_t (*altcp_get_tcp_addrinfo_fn)(struct altcp_pcb *conn, int local, ip
typedef ip_addr_t *(*altcp_get_ip_fn)(struct altcp_pcb *conn, int local); typedef ip_addr_t *(*altcp_get_ip_fn)(struct altcp_pcb *conn, int local);
typedef u16_t (*altcp_get_port_fn)(struct altcp_pcb *conn, int local); typedef u16_t (*altcp_get_port_fn)(struct altcp_pcb *conn, int local);
#if LWIP_TCP_KEEPALIVE
typedef void (*altcp_keepalive_disable_fn)(struct altcp_pcb *conn);
typedef void (*altcp_keepalive_enable_fn)(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count);
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
typedef enum tcp_state (*altcp_dbg_get_tcp_state_fn)(struct altcp_pcb *conn); typedef enum tcp_state (*altcp_dbg_get_tcp_state_fn)(struct altcp_pcb *conn);
#endif #endif
@ -111,6 +116,10 @@ struct altcp_functions {
altcp_get_tcp_addrinfo_fn addrinfo; altcp_get_tcp_addrinfo_fn addrinfo;
altcp_get_ip_fn getip; altcp_get_ip_fn getip;
altcp_get_port_fn getport; altcp_get_port_fn getport;
#if LWIP_TCP_KEEPALIVE
altcp_keepalive_disable_fn keepalive_disable;
altcp_keepalive_enable_fn keepalive_enable;
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
altcp_dbg_get_tcp_state_fn dbg_get_tcp_state; altcp_dbg_get_tcp_state_fn dbg_get_tcp_state;
#endif #endif
@ -133,6 +142,10 @@ void altcp_default_dealloc(struct altcp_pcb *conn);
err_t altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); err_t altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port);
ip_addr_t *altcp_default_get_ip(struct altcp_pcb *conn, int local); ip_addr_t *altcp_default_get_ip(struct altcp_pcb *conn, int local);
u16_t altcp_default_get_port(struct altcp_pcb *conn, int local); u16_t altcp_default_get_port(struct altcp_pcb *conn, int local);
#if LWIP_TCP_KEEPALIVE
void altcp_default_keepalive_disable(struct altcp_pcb *conn);
void altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count);
#endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn); enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn);
#endif #endif