]> git.lizzy.rs Git - rust.git/commitdiff
std::rt: Ignore 0-byte udp reads
authorBrian Anderson <banderson@mozilla.com>
Tue, 9 Jul 2013 23:54:48 +0000 (16:54 -0700)
committerBrian Anderson <banderson@mozilla.com>
Tue, 9 Jul 2013 23:54:56 +0000 (16:54 -0700)
src/libstd/rt/uv/net.rs

index b7caba849b7e10cf659e4844b478f2cba0fcded3..6d096f9885a7d7fe5f04fac28d99e170d6a67292 100644 (file)
@@ -392,6 +392,13 @@ pub fn recv_start(&self, alloc: AllocCallback, cb: UdpReceiveCallback) {
 
         extern fn recv_cb(handle: *uvll::uv_udp_t, nread: ssize_t, buf: Buf,
                           addr: *uvll::sockaddr, flags: c_uint) {
+            // When there's no data to read the recv callback can be a no-op.
+            // This can happen if read returns EAGAIN/EWOULDBLOCK. By ignoring
+            // this we just drop back to kqueue and wait for the next callback.
+            if nread == 0 {
+                return;
+            }
+
             rtdebug!("buf addr: %x", buf.base as uint);
             rtdebug!("buf len: %d", buf.len as int);
             let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);