aboutsummaryrefslogtreecommitdiff
path: root/src/sp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-10-13 12:05:12 -0700
committerGarrett D'Amore <garrett@damore.org>2024-10-13 12:45:15 -0700
commitb61285dc16974efe31a3b8d8923f17c8ce3cceb0 (patch)
treeb6dc0d8237144c969db92893c749616248d4f149 /src/sp
parent175a134b94dd3a3d77e6c3237408f102f2659288 (diff)
downloadnng-b61285dc16974efe31a3b8d8923f17c8ce3cceb0.tar.gz
nng-b61285dc16974efe31a3b8d8923f17c8ce3cceb0.tar.bz2
nng-b61285dc16974efe31a3b8d8923f17c8ce3cceb0.zip
udp: fix race, fix tests
Diffstat (limited to 'src/sp')
-rw-r--r--src/sp/transport/udp/udp.c12
-rw-r--r--src/sp/transport/udp/udp_tran_test.c6
2 files changed, 14 insertions, 4 deletions
diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c
index df5845fe..0e3b4ae8 100644
--- a/src/sp/transport/udp/udp.c
+++ b/src/sp/transport/udp/udp.c
@@ -969,6 +969,7 @@ udp_pipe_send(void *arg, nni_aio *aio)
udp_ep *ep;
udp_sp_data dreq;
nng_msg *msg;
+ size_t count = 0;
if (nni_aio_begin(aio) != 0) {
// No way to give the message back to the protocol,
@@ -981,6 +982,10 @@ udp_pipe_send(void *arg, nni_aio *aio)
msg = nni_aio_get_msg(aio);
ep = p->ep;
+ if (msg != NULL) {
+ count = nni_msg_len(msg) + nni_msg_header_len(msg);
+ }
+
nni_mtx_lock(&ep->mtx);
if ((nni_msg_len(msg) + nni_msg_header_len(msg)) > p->sndmax) {
nni_mtx_unlock(&ep->mtx);
@@ -999,14 +1004,13 @@ udp_pipe_send(void *arg, nni_aio *aio)
dreq.us_sender_id = p->self_id;
dreq.us_peer_id = p->peer_id;
dreq.us_sequence = p->self_seq++;
- dreq.us_length =
- msg != NULL ? nni_msg_len(msg) + nni_msg_header_len(msg) : 0;
+ dreq.us_length = (uint16_t) count;
// Just queue it, or fail it.
udp_queue_tx(ep, &p->peer_addr, (void *) &dreq, msg);
nni_mtx_unlock(&ep->mtx);
- nni_aio_finish(
- aio, 0, msg ? nni_msg_len(msg) + nni_msg_header_len(msg) : 0);
+
+ nni_aio_finish(aio, 0, count);
}
static void
diff --git a/src/sp/transport/udp/udp_tran_test.c b/src/sp/transport/udp/udp_tran_test.c
index 3b46c618..d68f60f9 100644
--- a/src/sp/transport/udp/udp_tran_test.c
+++ b/src/sp/transport/udp/udp_tran_test.c
@@ -273,6 +273,12 @@ test_udp_multi_small_burst(void)
int burst = 4;
int count = 20;
+#ifdef NNG_PLATFORM_WINDOWS
+ // Windows seems to drop a lot - maybe because of virtualization
+ burst = 2;
+ count = 10;
+#endif
+
// Experimentally at least on Darwin, we see some packet losses
// even for loopback. Loss rates appear depressingly high.
for (int i = 0; i < count; i++) {