ITADN

Socket: UDP recv timeout

#1449OpenSainan 创建于 2026-06-07
improvement
S
Sainancommented
Currently, `socket.recv` on a UDP socket can very easily block forever, whereas with TCP sockets, there is at least some hope of the underlying connection timing out, causing `recv` to return `nil`. Handling can easily be written in Pluto itself, e.g.: ```lua export function recv_with_timeout(s) local deadline = os.millis() + 3000 while deadline > os.millis() do if s:peek() then return s:recv() end end return nil -- same as socket.recv on a closed TCP socket end ``` However, this does feel like a bit of an oversight in the standard library function.
0 条评论