aboutsummaryrefslogtreecommitdiff
path: root/src/sp/transport/udp/udp.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-04 23:20:14 -0800
committerGarrett D'Amore <garrett@damore.org>2024-11-04 23:20:14 -0800
commita19dfb14c66d39c44a04aebd3b2b170a3111fd0f (patch)
treeabee02c42249704566a83074306ec7392ce6266c /src/sp/transport/udp/udp.c
parent75eb6f3cefe7979ede8c58cd6fde01ea1618cbbb (diff)
downloadnng-a19dfb14c66d39c44a04aebd3b2b170a3111fd0f.tar.gz
nng-a19dfb14c66d39c44a04aebd3b2b170a3111fd0f.tar.bz2
nng-a19dfb14c66d39c44a04aebd3b2b170a3111fd0f.zip
UDP: prefer new packets (drop older)
Adds test cases for this and for remote pipe as well.
Diffstat (limited to 'src/sp/transport/udp/udp.c')
-rw-r--r--src/sp/transport/udp/udp.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c
index 165b118d..25899070 100644
--- a/src/sp/transport/udp/udp.c
+++ b/src/sp/transport/udp/udp.c
@@ -676,9 +676,15 @@ udp_recv_data(udp_ep *ep, udp_sp_data *dreq, size_t len, nng_sockaddr *sa)
return;
}
+ // We have a choice to make. Drop this message (easiest), or
+ // drop the oldest. We drop the oldest because generally we
+ // find that applications prefer to have more recent data rather
+ // than keeping stale data.
if (nni_lmq_full(&p->rx_mq)) {
+ nni_msg *old;
+ (void) nni_lmq_get(&p->rx_mq, &old);
+ nni_msg_free(old);
nni_stat_inc(&ep->st_rcv_nobuf, 1);
- return;
}
// Short message, just alloc and copy