Skip to content

Commit 413d51e

Browse files
committed
std::rt: Ignore 0-byte udp reads
1 parent 6fb92f8 commit 413d51e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libstd/rt/uv/net.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@ impl UdpWatcher {
392392

393393
extern fn recv_cb(handle: *uvll::uv_udp_t, nread: ssize_t, buf: Buf,
394394
addr: *uvll::sockaddr, flags: c_uint) {
395+
// When there's no data to read the recv callback can be a no-op.
396+
// This can happen if read returns EAGAIN/EWOULDBLOCK. By ignoring
397+
// this we just drop back to kqueue and wait for the next callback.
398+
if nread == 0 {
399+
return;
400+
}
401+
395402
rtdebug!("buf addr: %x", buf.base as uint);
396403
rtdebug!("buf len: %d", buf.len as int);
397404
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);

0 commit comments

Comments
 (0)