Wait for `fd` to become readable. In this case, we return true. In case `abort_event` was signaled, return false.
(fd: &impl AsFd, abort_event: &impl AsRawFd)
| 199 | // Wait for `fd` to become readable. In this case, we return true. In case |
| 200 | // `abort_event` was signaled, return false. |
| 201 | fn wait_for_readable(fd: &impl AsFd, abort_event: &impl AsRawFd) -> Result<bool, io::Error> { |
| 202 | let fd = fd.as_fd().as_raw_fd(); |
| 203 | let abort_event = abort_event.as_raw_fd(); |
| 204 | |
| 205 | let mut poll_fds = [ |
| 206 | libc::pollfd { |
| 207 | fd: abort_event, |
| 208 | events: libc::POLLIN, |
| 209 | revents: 0, |
| 210 | }, |
| 211 | libc::pollfd { |
| 212 | fd, |
| 213 | events: libc::POLLIN, |
| 214 | revents: 0, |
| 215 | }, |
| 216 | ]; |
| 217 | |
| 218 | loop { |
| 219 | // SAFETY: This is safe, because the file descriptors are valid and the |
| 220 | // poll_fds array is properly initialized. |
| 221 | let ret = unsafe { libc::poll(poll_fds.as_mut_ptr(), poll_fds.len() as libc::nfds_t, -1) }; |
| 222 | |
| 223 | if ret >= 0 { |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | let err = io::Error::last_os_error(); |
| 228 | if err.raw_os_error() == Some(libc::EINTR) { |
| 229 | continue; |
| 230 | } |
| 231 | |
| 232 | return Err(err); |
| 233 | } |
| 234 | |
| 235 | if poll_fds[0].revents & libc::POLLIN != 0 { |
| 236 | return Ok(false); |
| 237 | } |
| 238 | |
| 239 | if poll_fds[1].revents & libc::POLLIN != 0 { |
| 240 | return Ok(true); |
| 241 | } |
| 242 | |
| 243 | Err(io::Error::other( |
| 244 | "Poll returned, but neither file descriptor is readable?", |
| 245 | )) |
| 246 | } |
| 247 | |
| 248 | /// Struct to keep track of additional connections for receiving VM migration data. |
| 249 | #[derive(Debug)] |
no test coverage detected