diff --git a/stdlib/Sockets/src/Sockets.jl b/stdlib/Sockets/src/Sockets.jl index 7a1726f6c385be..9b25c43908e4c5 100644 --- a/stdlib/Sockets/src/Sockets.jl +++ b/stdlib/Sockets/src/Sockets.jl @@ -331,6 +331,17 @@ Read a UDP packet from the specified socket, returning a tuple of `(address, dat `address` will be either IPv4 or IPv6 as appropriate. """ function recvfrom(sock::UDPSocket) + from, data = recvfrom2(sock) + return (from.host, data) +end + +""" + recvfrom2(socket::UDPSocket) -> (host_port, data) + +Read a UDP packet from the specified socket, returning a tuple of `(host_port, data)`, where +`host_port` will be an InetAddr{IPv4} or InetAddr{IPv6}, as appropriate. +""" +function recvfrom2(sock::UDPSocket) iolock_begin() # If the socket has not been bound, it will be bound implicitly to ::0 and a random port if sock.status != StatusInit && sock.status != StatusOpen && sock.status != StatusActive @@ -348,7 +359,7 @@ function recvfrom(sock::UDPSocket) From = Union{InetAddr{IPv4}, InetAddr{IPv6}} Data = Vector{UInt8} from, data = wait(sock.recvnotify)::Tuple{From, Data} - return (from.host, data) + return (from, data) finally unlock(sock.recvnotify) end