From c031f60599cfdf4816cef57ace42ddeaba6f7375 Mon Sep 17 00:00:00 2001
From: "carpentry-heartbeat[bot]"
Date: Mon, 13 Jul 2026 05:14:41 +0200
Subject: [PATCH] Fix UdpSocket.recv-from truncating datagrams larger than 4096
bytes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
recv-from allocated a fixed 4096-byte receive buffer, and recvfrom fills
at most buf->capacity before silently discarding the rest of the
datagram. Any UDP datagram larger than 4096 bytes was therefore
truncated with no error — silent data loss. Size the buffer to the
maximum UDP payload (65535 bytes) so a datagram is received whole.
Also add UdpSocket.local-port (mirroring TcpListener.local-port) so a
socket bound to port 0 can report its OS-assigned port, and add the
repo's first UDP test suite: a loopback round-trip that verifies small,
over-4096, and 60000-byte datagrams all arrive intact.
---
docs/UdpSocket.html | 23 ++++++++++++++++++++-
src/udp_socket.carp | 11 ++++++++--
src/udp_socket.h | 2 ++
test/udp_test.carp | 49 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+), 3 deletions(-)
create mode 100644 test/udp_test.carp
diff --git a/docs/UdpSocket.html b/docs/UdpSocket.html
index 96cf096..16466f3 100644
--- a/docs/UdpSocket.html
+++ b/docs/UdpSocket.html
@@ -122,6 +122,27 @@
+
+
+
+ local-port
+
+
+
+ external
+
+
+ (Fn [(Ref UdpSocket a)] Int)
+
+
+
+
+
+
returns the port the socket is bound to. Useful
+after binding to port 0 to discover the OS-assigned port.
+
+
+