diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c index df5845fe8..0e3b4ae80 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 3b46c618d..d68f60f9f 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++) {