From: Guus Sliepen Date: Sun, 19 Apr 2020 14:24:20 +0000 (+0200) Subject: Add a callback that is triggered when the retransmission timeout expires. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=1d5bafdfb2ca9d357ee3099baf4cce5e92f89527;p=utcp Add a callback that is triggered when the retransmission timeout expires. This can be used by the application to detect potential network problems. --- diff --git a/utcp.c b/utcp.c index 19f6cfa..20d86c2 100644 --- a/utcp.c +++ b/utcp.c @@ -890,6 +890,10 @@ static void retransmit(struct utcp_connection *c) { struct utcp *utcp = c->utcp; + if (utcp->retransmit) { + utcp->retransmit(c); + } + struct { struct hdr hdr; uint8_t data[]; @@ -2447,6 +2451,10 @@ void utcp_offline(struct utcp *utcp, bool offline) { } } +void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t retransmit) { + utcp->retransmit = retransmit; +} + void utcp_set_clock_granularity(long granularity) { CLOCK_GRANULARITY = granularity; } diff --git a/utcp.h b/utcp.h index aed177c..ff509ac 100644 --- a/utcp.h +++ b/utcp.h @@ -56,6 +56,7 @@ struct utcp_connection; typedef bool (*utcp_pre_accept_t)(struct utcp *utcp, uint16_t port); typedef void (*utcp_accept_t)(struct utcp_connection *utcp_connection, uint16_t port); +typedef void (*utcp_retransmit_t)(struct utcp_connection *connection); typedef ssize_t (*utcp_send_t)(struct utcp *utcp, const void *data, size_t len); typedef ssize_t (*utcp_recv_t)(struct utcp_connection *connection, const void *data, size_t len); @@ -92,6 +93,7 @@ extern void utcp_set_mtu(struct utcp *utcp, uint16_t mtu); extern void utcp_reset_timers(struct utcp *utcp); extern void utcp_offline(struct utcp *utcp, bool offline); +extern void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t retransmit); // Per-socket options diff --git a/utcp_priv.h b/utcp_priv.h index 58e2715..197fd26 100644 --- a/utcp_priv.h +++ b/utcp_priv.h @@ -178,6 +178,7 @@ struct utcp { utcp_accept_t accept; utcp_pre_accept_t pre_accept; + utcp_retransmit_t retransmit; utcp_send_t send; // Packet buffer