Debian Codegraph @

debian/rust-vendor/nix/src/sys/aio.rs

raw
1 // vim: tw=80
2 //! POSIX Asynchronous I/O
3 //!
4 //! The POSIX AIO interface is used for asynchronous I/O on files and disk-like
5 //! devices. It supports [`read`](struct.AioRead.html#method.new),
6 //! [`write`](struct.AioWrite.html#method.new),
7 //! [`fsync`](struct.AioFsync.html#method.new),
8 //! [`readv`](struct.AioReadv.html#method.new), and
9 //! [`writev`](struct.AioWritev.html#method.new), operations, subject to
10 //! platform support. Completion
11 //! notifications can optionally be delivered via
12 //! [signals](../signal/enum.SigevNotify.html#variant.SigevSignal), via the
13 //! [`aio_suspend`](fn.aio_suspend.html) function, or via polling. Some
14 //! platforms support other completion
15 //! notifications, such as
16 //! [kevent](../signal/enum.SigevNotify.html#variant.SigevKevent).
17 //!
18 //! Multiple operations may be submitted in a batch with
19 //! [`lio_listio`](fn.lio_listio.html), though the standard does not guarantee
20 //! that they will be executed atomically.
21 //!
22 //! Outstanding operations may be cancelled with
23 //! [`cancel`](trait.Aio.html#method.cancel) or
24 //! [`aio_cancel_all`](fn.aio_cancel_all.html), though the operating system may
25 //! not support this for all filesystems and devices.
26 #![allow(clippy::doc_overindented_list_items)] // It looks better this way
27 #[cfg(target_os = "freebsd")]
28 use std::io::{IoSlice, IoSliceMut};
29 use std::{
30 convert::TryFrom,
31 fmt::{self, Debug},
32 marker::{PhantomData, PhantomPinned},
33 mem,
34 os::unix::io::{AsFd, AsRawFd, BorrowedFd},
35 pin::Pin,
36 ptr, thread,
37 };
38
39 use libc::off_t;
40 use pin_utils::unsafe_pinned;
41
42 use crate::{
43 errno::Errno,
44 sys::{signal::*, time::TimeSpec},
45 Result,
46 };
47
48 libc_enum! {
49 /// Mode for `AioCb::fsync`. Controls whether only data or both data and
50 /// metadata are synced.
51 #[repr(i32)]
52 #[non_exhaustive]
53 pub enum AioFsyncMode {
54 /// do it like `fsync`
55 O_SYNC,
56 /// on supported operating systems only, do it like `fdatasync`
57 #[cfg(any(apple_targets,
58 target_os = "linux",
59 target_os = "freebsd",
60 netbsdlike))]
61 O_DSYNC
62 }
63 impl TryFrom<i32>
64 }
65
66 libc_enum! {
67 /// Mode for [`lio_listio`](fn.lio_listio.html)
68 #[repr(i32)]
69 pub enum LioMode {
70 /// Requests that [`lio_listio`](fn.lio_listio.html) block until all
71 /// requested operations have been completed
72 LIO_WAIT,
73 /// Requests that [`lio_listio`](fn.lio_listio.html) return immediately
74 LIO_NOWAIT,
75 }
76 }
77
78 /// Return values for [`AioCb::cancel`](struct.AioCb.html#method.cancel) and
79 /// [`aio_cancel_all`](fn.aio_cancel_all.html)
80 #[repr(i32)]
81 #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
82 pub enum AioCancelStat {
83 /// All outstanding requests were canceled
84 AioCanceled = libc::AIO_CANCELED,
85 /// Some requests were not canceled. Their status should be checked with
86 /// `AioCb::error`
87 AioNotCanceled = libc::AIO_NOTCANCELED,
88 /// All of the requests have already finished
89 AioAllDone = libc::AIO_ALLDONE,
90 }
91
92 /// Newtype that adds Send and Sync to libc::aiocb, which contains raw pointers
93 #[repr(transparent)]
94 struct LibcAiocb(libc::aiocb);
95
96 unsafe impl Send for LibcAiocb {}
97 unsafe impl Sync for LibcAiocb {}
98
99 /// Base class for all AIO operations. Should only be used directly when
100 /// checking for completion.
101 // We could create some kind of AsPinnedMut trait, and implement it for all aio
102 // ops, allowing the crate's users to get pinned references to `AioCb`. That
103 // could save some code for things like polling methods. But IMHO it would
104 // provide polymorphism at the wrong level. Instead, the best place for
105 // polymorphism is at the level of `Futures`.
106 #[repr(C)]
107 struct AioCb<'a> {
108 aiocb: LibcAiocb,
109 /// Could this `AioCb` potentially have any in-kernel state?
110 // It would be really nice to perform the in-progress check entirely at
111 // compile time. But I can't figure out how, because:
112 // * Future::poll takes a `Pin<&mut self>` rather than `self`, and
113 // * Rust's lack of an equivalent of C++'s Guaranteed Copy Elision means
114 // that there's no way to write an AioCb constructor that neither boxes
115 // the object itself, nor moves it during return.
116 in_progress: bool,
117 _fd: PhantomData<BorrowedFd<'a>>,
118 }
119
120 impl<'a> AioCb<'a> {
121 pin_utils::unsafe_unpinned!(aiocb: LibcAiocb);
122
123 fn aio_return(mut self: Pin<&mut Self>) -> Result<usize> {
124 self.in_progress = false;
125 unsafe {
126 let p: *mut libc::aiocb = &mut self.aiocb.0;
127 Errno::result(libc::aio_return(p))
128 }
129 .map(|r| r as usize)
130 }
131
132 fn cancel(mut self: Pin<&mut Self>) -> Result<AioCancelStat> {
133 let r = unsafe {
134 libc::aio_cancel(self.aiocb.0.aio_fildes, &mut self.aiocb.0)
135 };
136 match r {
137 libc::AIO_CANCELED => Ok(AioCancelStat::AioCanceled),
138 libc::AIO_NOTCANCELED => Ok(AioCancelStat::AioNotCanceled),
139 libc::AIO_ALLDONE => Ok(AioCancelStat::AioAllDone),
140 -1 => Err(Errno::last()),
141 _ => panic!("unknown aio_cancel return value"),
142 }
143 }
144
145 fn common_init(
146 fd: BorrowedFd<'a>,
147 prio: i32,
148 sigev_notify: SigevNotify,
149 ) -> Self {
150 // Use mem::zeroed instead of explicitly zeroing each field, because the
151 // number and name of reserved fields is OS-dependent. On some OSes,
152 // some reserved fields are used the kernel for state, and must be
153 // explicitly zeroed when allocated.
154 let mut a = unsafe { mem::zeroed::<libc::aiocb>() };
155 a.aio_fildes = fd.as_raw_fd();
156 a.aio_reqprio = prio;
157 a.aio_sigevent = SigEvent::new(sigev_notify).sigevent();
158 AioCb {
159 aiocb: LibcAiocb(a),
160 in_progress: false,
161 _fd: PhantomData,
162 }
163 }
164
165 fn error(self: Pin<&mut Self>) -> Result<()> {
166 let r = unsafe { libc::aio_error(&self.aiocb().0) };
167 match r {
168 0 => Ok(()),
169 num if num > 0 => Err(Errno::from_raw(num)),
170 -1 => Err(Errno::last()),
171 num => panic!("unknown aio_error return value {num:?}"),
172 }
173 }
174
175 fn in_progress(&self) -> bool {
176 self.in_progress
177 }
178
179 fn set_in_progress(mut self: Pin<&mut Self>) {
180 self.as_mut().in_progress = true;
181 }
182
183 /// Update the notification settings for an existing AIO operation that has
184 /// not yet been submitted.
185 // Takes a normal reference rather than a pinned one because this method is
186 // normally called before the object needs to be pinned, that is, before
187 // it's been submitted to the kernel.
188 fn set_sigev_notify(&mut self, sigev_notify: SigevNotify) {
189 assert!(
190 !self.in_progress,
191 "Can't change notification settings for an in-progress operation"
192 );
193 self.aiocb.0.aio_sigevent = SigEvent::new(sigev_notify).sigevent();
194 }
195 }
196
197 impl Debug for AioCb<'_> {
198 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
199 fmt.debug_struct("AioCb")
200 .field("aiocb", &self.aiocb.0)
201 .field("in_progress", &self.in_progress)
202 .finish()
203 }
204 }
205
206 impl Drop for AioCb<'_> {
207 /// If the `AioCb` has no remaining state in the kernel, just drop it.
208 /// Otherwise, dropping constitutes a resource leak, which is an error
209 fn drop(&mut self) {
210 assert!(
211 thread::panicking() || !self.in_progress,
212 "Dropped an in-progress AioCb"
213 );
214 }
215 }
216
217 /// Methods common to all AIO operations
218 pub trait Aio {
219 /// The return type of [`Aio::aio_return`].
220 type Output;
221
222 /// Retrieve return status of an asynchronous operation.
223 ///
224 /// Should only be called once for each operation, after [`Aio::error`]
225 /// indicates that it has completed. The result is the same as for the
226 /// synchronous `read(2)`, `write(2)`, of `fsync(2)` functions.
227 ///
228 /// # References
229 ///
230 /// [aio_return](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_return.html)
231 fn aio_return(self: Pin<&mut Self>) -> Result<Self::Output>;
232
233 /// Cancels an outstanding AIO request.
234 ///
235 /// The operating system is not required to implement cancellation for all
236 /// file and device types. Even if it does, there is no guarantee that the
237 /// operation has not already completed. So the caller must check the
238 /// result and handle operations that were not canceled or that have already
239 /// completed.
240 ///
241 /// # Examples
242 ///
243 /// Cancel an outstanding aio operation. Note that we must still call
244 /// `aio_return` to free resources, even though we don't care about the
245 /// result.
246 ///
247 /// ```
248 /// # use nix::errno::Errno;
249 /// # use nix::Error;
250 /// # use nix::sys::aio::*;
251 /// # use nix::sys::signal::SigevNotify;
252 /// # use std::{thread, time};
253 /// # use std::io::Write;
254 /// # use std::os::unix::io::AsFd;
255 /// # use tempfile::tempfile;
256 /// let wbuf = b"CDEF";
257 /// let mut f = tempfile().unwrap();
258 /// let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
259 /// 2, //offset
260 /// &wbuf[..],
261 /// 0, //priority
262 /// SigevNotify::SigevNone));
263 /// aiocb.as_mut().submit().unwrap();
264 /// let cs = aiocb.as_mut().cancel().unwrap();
265 /// if cs == AioCancelStat::AioNotCanceled {
266 /// while (aiocb.as_mut().error() == Err(Errno::EINPROGRESS)) {
267 /// thread::sleep(time::Duration::from_millis(10));
268 /// }
269 /// }
270 /// // Must call `aio_return`, but ignore the result
271 /// let _ = aiocb.as_mut().aio_return();
272 /// ```
273 ///
274 /// # References
275 ///
276 /// [aio_cancel](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_cancel.html)
277 fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat>;
278
279 /// Retrieve error status of an asynchronous operation.
280 ///
281 /// If the request has not yet completed, returns `EINPROGRESS`. Otherwise,
282 /// returns `Ok` or any other error.
283 ///
284 /// # Examples
285 ///
286 /// Issue an aio operation and use `error` to poll for completion. Polling
287 /// is an alternative to `aio_suspend`, used by most of the other examples.
288 ///
289 /// ```
290 /// # use nix::errno::Errno;
291 /// # use nix::Error;
292 /// # use nix::sys::aio::*;
293 /// # use nix::sys::signal::SigevNotify;
294 /// # use std::{thread, time};
295 /// # use std::os::unix::io::AsFd;
296 /// # use tempfile::tempfile;
297 /// const WBUF: &[u8] = b"abcdef123456";
298 /// let mut f = tempfile().unwrap();
299 /// let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
300 /// 2, //offset
301 /// WBUF,
302 /// 0, //priority
303 /// SigevNotify::SigevNone));
304 /// aiocb.as_mut().submit().unwrap();
305 /// while (aiocb.as_mut().error() == Err(Errno::EINPROGRESS)) {
306 /// thread::sleep(time::Duration::from_millis(10));
307 /// }
308 /// assert_eq!(aiocb.as_mut().aio_return().unwrap(), WBUF.len());
309 /// ```
310 ///
311 /// # References
312 ///
313 /// [aio_error](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_error.html)
314 fn error(self: Pin<&mut Self>) -> Result<()>;
315
316 /// Returns the underlying file descriptor associated with the operation.
317 fn fd(&self) -> BorrowedFd<'_>;
318
319 /// Does this operation currently have any in-kernel state?
320 ///
321 /// Dropping an operation that does have in-kernel state constitutes a
322 /// resource leak.
323 ///
324 /// # Examples
325 ///
326 /// ```
327 /// # use nix::errno::Errno;
328 /// # use nix::Error;
329 /// # use nix::sys::aio::*;
330 /// # use nix::sys::signal::SigevNotify::SigevNone;
331 /// # use std::{thread, time};
332 /// # use std::os::unix::io::AsFd;
333 /// # use tempfile::tempfile;
334 /// let f = tempfile().unwrap();
335 /// let mut aiof = Box::pin(AioFsync::new(f.as_fd(), AioFsyncMode::O_SYNC,
336 /// 0, SigevNone));
337 /// assert!(!aiof.as_mut().in_progress());
338 /// aiof.as_mut().submit().expect("aio_fsync failed early");
339 /// assert!(aiof.as_mut().in_progress());
340 /// while (aiof.as_mut().error() == Err(Errno::EINPROGRESS)) {
341 /// thread::sleep(time::Duration::from_millis(10));
342 /// }
343 /// aiof.as_mut().aio_return().expect("aio_fsync failed late");
344 /// assert!(!aiof.as_mut().in_progress());
345 /// ```
346 fn in_progress(&self) -> bool;
347
348 /// Returns the priority of the `AioCb`
349 fn priority(&self) -> i32;
350
351 /// Update the notification settings for an existing AIO operation that has
352 /// not yet been submitted.
353 fn set_sigev_notify(&mut self, sev: SigevNotify);
354
355 /// Returns the `SigEvent` that will be used for notification.
356 fn sigevent(&self) -> SigEvent;
357
358 /// Actually start the I/O operation.
359 ///
360 /// After calling this method and until [`Aio::aio_return`] returns `Ok`,
361 /// the structure may not be moved in memory.
362 fn submit(self: Pin<&mut Self>) -> Result<()>;
363 }
364
365 macro_rules! aio_methods {
366 () => {
367 fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat> {
368 self.aiocb().cancel()
369 }
370
371 fn error(self: Pin<&mut Self>) -> Result<()> {
372 self.aiocb().error()
373 }
374
375 fn fd(&self) -> BorrowedFd<'a> {
376 // safe because self's lifetime is the same as the original file
377 // descriptor.
378 unsafe { BorrowedFd::borrow_raw(self.aiocb.aiocb.0.aio_fildes) }
379 }
380
381 fn in_progress(&self) -> bool {
382 self.aiocb.in_progress()
383 }
384
385 fn priority(&self) -> i32 {
386 self.aiocb.aiocb.0.aio_reqprio
387 }
388
389 fn set_sigev_notify(&mut self, sev: SigevNotify) {
390 self.aiocb.set_sigev_notify(sev)
391 }
392
393 fn sigevent(&self) -> SigEvent {
394 SigEvent::from(&self.aiocb.aiocb.0.aio_sigevent)
395 }
396 };
397 ($func:ident) => {
398 aio_methods!();
399
400 fn aio_return(self: Pin<&mut Self>) -> Result<<Self as Aio>::Output> {
401 self.aiocb().aio_return()
402 }
403
404 fn submit(mut self: Pin<&mut Self>) -> Result<()> {
405 let p: *mut libc::aiocb = &mut self.as_mut().aiocb().aiocb.0;
406 Errno::result({ unsafe { libc::$func(p) } }).map(|_| {
407 self.aiocb().set_in_progress();
408 })
409 }
410 };
411 }
412
413 /// An asynchronous version of `fsync(2)`.
414 ///
415 /// # References
416 ///
417 /// [aio_fsync](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_fsync.html)
418 /// # Examples
419 ///
420 /// ```
421 /// # use nix::errno::Errno;
422 /// # use nix::Error;
423 /// # use nix::sys::aio::*;
424 /// # use nix::sys::signal::SigevNotify::SigevNone;
425 /// # use std::{thread, time};
426 /// # use std::os::unix::io::AsFd;
427 /// # use tempfile::tempfile;
428 /// let f = tempfile().unwrap();
429 /// let mut aiof = Box::pin(AioFsync::new(f.as_fd(), AioFsyncMode::O_SYNC,
430 /// 0, SigevNone));
431 /// aiof.as_mut().submit().expect("aio_fsync failed early");
432 /// while (aiof.as_mut().error() == Err(Errno::EINPROGRESS)) {
433 /// thread::sleep(time::Duration::from_millis(10));
434 /// }
435 /// aiof.as_mut().aio_return().expect("aio_fsync failed late");
436 /// ```
437 #[derive(Debug)]
438 #[repr(transparent)]
439 pub struct AioFsync<'a> {
440 aiocb: AioCb<'a>,
441 _pin: PhantomPinned,
442 }
443
444 impl<'a> AioFsync<'a> {
445 unsafe_pinned!(aiocb: AioCb<'a>);
446
447 /// Returns the operation's fsync mode: data and metadata or data only?
448 pub fn mode(&self) -> AioFsyncMode {
449 AioFsyncMode::try_from(self.aiocb.aiocb.0.aio_lio_opcode).unwrap()
450 }
451
452 /// Create a new `AioFsync`.
453 ///
454 /// # Arguments
455 ///
456 /// * `fd`: File descriptor to sync.
457 /// * `mode`: Whether to sync file metadata too, or just data.
458 /// * `prio`: If POSIX Prioritized IO is supported, then the
459 /// operation will be prioritized at the process's priority level minus
460 /// `prio`.
461 /// * `sigev_notify`: Determines how you will be notified of event completion.
462 pub fn new(
463 fd: BorrowedFd<'a>,
464 mode: AioFsyncMode,
465 prio: i32,
466 sigev_notify: SigevNotify,
467 ) -> Self {
468 let mut aiocb = AioCb::common_init(fd, prio, sigev_notify);
469 // To save some memory, store mode in an unused field of the AioCb.
470 // True it isn't very much memory, but downstream creates will likely
471 // create an enum containing this and other AioCb variants and pack
472 // those enums into data structures like Vec, so it adds up.
473 aiocb.aiocb.0.aio_lio_opcode = mode as libc::c_int;
474 AioFsync {
475 aiocb,
476 _pin: PhantomPinned,
477 }
478 }
479 }
480
481 impl<'a> Aio for AioFsync<'a> {
482 type Output = ();
483
484 aio_methods!();
485
486 fn aio_return(self: Pin<&mut Self>) -> Result<()> {
487 self.aiocb().aio_return().map(drop)
488 }
489
490 fn submit(mut self: Pin<&mut Self>) -> Result<()> {
491 let aiocb = &mut self.as_mut().aiocb().aiocb.0;
492 let mode = mem::replace(&mut aiocb.aio_lio_opcode, 0);
493 let p: *mut libc::aiocb = aiocb;
494 Errno::result(unsafe { libc::aio_fsync(mode, p) }).map(|_| {
495 self.aiocb().set_in_progress();
496 })
497 }
498 }
499
500 // AioFsync does not need AsMut, since it can't be used with lio_listio
501
502 impl AsRef<libc::aiocb> for AioFsync<'_> {
503 fn as_ref(&self) -> &libc::aiocb {
504 &self.aiocb.aiocb.0
505 }
506 }
507
508 /// Asynchronously reads from a file descriptor into a buffer
509 ///
510 /// # References
511 ///
512 /// [aio_read](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_read.html)
513 ///
514 /// # Examples
515 ///
516 ///
517 /// ```
518 /// # use nix::errno::Errno;
519 /// # use nix::Error;
520 /// # use nix::sys::aio::*;
521 /// # use nix::sys::signal::SigevNotify;
522 /// # use std::{thread, time};
523 /// # use std::io::Write;
524 /// # use std::os::unix::io::AsFd;
525 /// # use tempfile::tempfile;
526 /// const INITIAL: &[u8] = b"abcdef123456";
527 /// const LEN: usize = 4;
528 /// let mut rbuf = vec![0; LEN];
529 /// let mut f = tempfile().unwrap();
530 /// f.write_all(INITIAL).unwrap();
531 /// {
532 /// let mut aior = Box::pin(
533 /// AioRead::new(
534 /// f.as_fd(),
535 /// 2, //offset
536 /// &mut rbuf,
537 /// 0, //priority
538 /// SigevNotify::SigevNone
539 /// )
540 /// );
541 /// aior.as_mut().submit().unwrap();
542 /// while (aior.as_mut().error() == Err(Errno::EINPROGRESS)) {
543 /// thread::sleep(time::Duration::from_millis(10));
544 /// }
545 /// assert_eq!(aior.as_mut().aio_return().unwrap(), LEN);
546 /// }
547 /// assert_eq!(rbuf, b"cdef");
548 /// ```
549 #[derive(Debug)]
550 #[repr(transparent)]
551 pub struct AioRead<'a> {
552 aiocb: AioCb<'a>,
553 _data: PhantomData<&'a [u8]>,
554 _pin: PhantomPinned,
555 }
556
557 impl<'a> AioRead<'a> {
558 unsafe_pinned!(aiocb: AioCb<'a>);
559
560 /// Returns the requested length of the aio operation in bytes
561 ///
562 /// This method returns the *requested* length of the operation. To get the
563 /// number of bytes actually read or written by a completed operation, use
564 /// `aio_return` instead.
565 pub fn nbytes(&self) -> usize {
566 self.aiocb.aiocb.0.aio_nbytes
567 }
568
569 /// Create a new `AioRead`, placing the data in a mutable slice.
570 ///
571 /// # Arguments
572 ///
573 /// * `fd`: File descriptor to read from
574 /// * `offs`: File offset
575 /// * `buf`: A memory buffer. It must outlive the `AioRead`.
576 /// * `prio`: If POSIX Prioritized IO is supported, then the
577 /// operation will be prioritized at the process's
578 /// priority level minus `prio`.
579 /// * `sigev_notify`: Determines how you will be notified of event completion.
580 pub fn new(
581 fd: BorrowedFd<'a>,
582 offs: off_t,
583 buf: &'a mut [u8],
584 prio: i32,
585 sigev_notify: SigevNotify,
586 ) -> Self {
587 let mut aiocb = AioCb::common_init(fd, prio, sigev_notify);
588 aiocb.aiocb.0.aio_nbytes = buf.len();
589 aiocb.aiocb.0.aio_buf = buf.as_mut_ptr().cast();
590 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_READ;
591 aiocb.aiocb.0.aio_offset = offs;
592 AioRead {
593 aiocb,
594 _data: PhantomData,
595 _pin: PhantomPinned,
596 }
597 }
598
599 /// Returns the file offset of the operation.
600 pub fn offset(&self) -> off_t {
601 self.aiocb.aiocb.0.aio_offset
602 }
603 }
604
605 impl<'a> Aio for AioRead<'a> {
606 type Output = usize;
607
608 aio_methods!(aio_read);
609 }
610
611 impl AsMut<libc::aiocb> for AioRead<'_> {
612 fn as_mut(&mut self) -> &mut libc::aiocb {
613 &mut self.aiocb.aiocb.0
614 }
615 }
616
617 impl AsRef<libc::aiocb> for AioRead<'_> {
618 fn as_ref(&self) -> &libc::aiocb {
619 &self.aiocb.aiocb.0
620 }
621 }
622
623 /// Asynchronously reads from a file descriptor into a scatter/gather list of buffers.
624 ///
625 /// # References
626 ///
627 /// [aio_readv](https://www.freebsd.org/cgi/man.cgi?query=aio_readv)
628 ///
629 /// # Examples
630 ///
631 ///
632 #[cfg_attr(fbsd14, doc = " ```")]
633 #[cfg_attr(not(fbsd14), doc = " ```no_run")]
634 /// # use nix::errno::Errno;
635 /// # use nix::Error;
636 /// # use nix::sys::aio::*;
637 /// # use nix::sys::signal::SigevNotify;
638 /// # use std::{thread, time};
639 /// # use std::io::{IoSliceMut, Write};
640 /// # use std::os::unix::io::AsFd;
641 /// # use tempfile::tempfile;
642 /// const INITIAL: &[u8] = b"abcdef123456";
643 /// let mut rbuf0 = vec![0; 4];
644 /// let mut rbuf1 = vec![0; 2];
645 /// let expected_len = rbuf0.len() + rbuf1.len();
646 /// let mut rbufs = [IoSliceMut::new(&mut rbuf0), IoSliceMut::new(&mut rbuf1)];
647 /// let mut f = tempfile().unwrap();
648 /// f.write_all(INITIAL).unwrap();
649 /// {
650 /// let mut aior = Box::pin(
651 /// AioReadv::new(
652 /// f.as_fd(),
653 /// 2, //offset
654 /// &mut rbufs,
655 /// 0, //priority
656 /// SigevNotify::SigevNone
657 /// )
658 /// );
659 /// aior.as_mut().submit().unwrap();
660 /// while (aior.as_mut().error() == Err(Errno::EINPROGRESS)) {
661 /// thread::sleep(time::Duration::from_millis(10));
662 /// }
663 /// assert_eq!(aior.as_mut().aio_return().unwrap(), expected_len);
664 /// }
665 /// assert_eq!(rbuf0, b"cdef");
666 /// assert_eq!(rbuf1, b"12");
667 /// ```
668 #[cfg(target_os = "freebsd")]
669 #[derive(Debug)]
670 #[repr(transparent)]
671 pub struct AioReadv<'a> {
672 aiocb: AioCb<'a>,
673 _data: PhantomData<&'a [&'a [u8]]>,
674 _pin: PhantomPinned,
675 }
676
677 #[cfg(target_os = "freebsd")]
678 impl<'a> AioReadv<'a> {
679 unsafe_pinned!(aiocb: AioCb<'a>);
680
681 /// Returns the number of buffers the operation will read into.
682 pub fn iovlen(&self) -> usize {
683 self.aiocb.aiocb.0.aio_nbytes
684 }
685
686 /// Create a new `AioReadv`, placing the data in a list of mutable slices.
687 ///
688 /// # Arguments
689 ///
690 /// * `fd`: File descriptor to read from
691 /// * `offs`: File offset
692 /// * `bufs`: A scatter/gather list of memory buffers. They must
693 /// outlive the `AioReadv`.
694 /// * `prio`: If POSIX Prioritized IO is supported, then the
695 /// operation will be prioritized at the process's
696 /// priority level minus `prio`
697 /// * `sigev_notify`: Determines how you will be notified of event
698 /// completion.
699 pub fn new(
700 fd: BorrowedFd<'a>,
701 offs: off_t,
702 bufs: &mut [IoSliceMut<'a>],
703 prio: i32,
704 sigev_notify: SigevNotify,
705 ) -> Self {
706 let mut aiocb = AioCb::common_init(fd, prio, sigev_notify);
707 // In vectored mode, aio_nbytes stores the length of the iovec array,
708 // not the byte count.
709 aiocb.aiocb.0.aio_nbytes = bufs.len();
710 aiocb.aiocb.0.aio_buf = bufs.as_mut_ptr().cast();
711 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_READV;
712 aiocb.aiocb.0.aio_offset = offs;
713 AioReadv {
714 aiocb,
715 _data: PhantomData,
716 _pin: PhantomPinned,
717 }
718 }
719
720 /// Returns the file offset of the operation.
721 pub fn offset(&self) -> off_t {
722 self.aiocb.aiocb.0.aio_offset
723 }
724 }
725
726 #[cfg(target_os = "freebsd")]
727 impl<'a> Aio for AioReadv<'a> {
728 type Output = usize;
729
730 aio_methods!(aio_readv);
731 }
732
733 #[cfg(target_os = "freebsd")]
734 impl AsMut<libc::aiocb> for AioReadv<'_> {
735 fn as_mut(&mut self) -> &mut libc::aiocb {
736 &mut self.aiocb.aiocb.0
737 }
738 }
739
740 #[cfg(target_os = "freebsd")]
741 impl AsRef<libc::aiocb> for AioReadv<'_> {
742 fn as_ref(&self) -> &libc::aiocb {
743 &self.aiocb.aiocb.0
744 }
745 }
746
747 /// Asynchronously writes from a buffer to a file descriptor
748 ///
749 /// # References
750 ///
751 /// [aio_write](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_write.html)
752 ///
753 /// # Examples
754 ///
755 /// ```
756 /// # use nix::errno::Errno;
757 /// # use nix::Error;
758 /// # use nix::sys::aio::*;
759 /// # use nix::sys::signal::SigevNotify;
760 /// # use std::{thread, time};
761 /// # use std::os::unix::io::AsFd;
762 /// # use tempfile::tempfile;
763 /// const WBUF: &[u8] = b"abcdef123456";
764 /// let mut f = tempfile().unwrap();
765 /// let mut aiow = Box::pin(
766 /// AioWrite::new(
767 /// f.as_fd(),
768 /// 2, //offset
769 /// WBUF,
770 /// 0, //priority
771 /// SigevNotify::SigevNone
772 /// )
773 /// );
774 /// aiow.as_mut().submit().unwrap();
775 /// while (aiow.as_mut().error() == Err(Errno::EINPROGRESS)) {
776 /// thread::sleep(time::Duration::from_millis(10));
777 /// }
778 /// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len());
779 /// ```
780 #[derive(Debug)]
781 #[repr(transparent)]
782 pub struct AioWrite<'a> {
783 aiocb: AioCb<'a>,
784 _data: PhantomData<&'a [u8]>,
785 _pin: PhantomPinned,
786 }
787
788 impl<'a> AioWrite<'a> {
789 unsafe_pinned!(aiocb: AioCb<'a>);
790
791 /// Returns the requested length of the aio operation in bytes
792 ///
793 /// This method returns the *requested* length of the operation. To get the
794 /// number of bytes actually read or written by a completed operation, use
795 /// `aio_return` instead.
796 pub fn nbytes(&self) -> usize {
797 self.aiocb.aiocb.0.aio_nbytes
798 }
799
800 /// Construct a new `AioWrite`.
801 ///
802 /// # Arguments
803 ///
804 /// * `fd`: File descriptor to write to
805 /// * `offs`: File offset
806 /// * `buf`: A memory buffer. It must outlive the `AioWrite`.
807 /// * `prio`: If POSIX Prioritized IO is supported, then the
808 /// operation will be prioritized at the process's
809 /// priority level minus `prio`
810 /// * `sigev_notify`: Determines how you will be notified of event completion.
811 pub fn new(
812 fd: BorrowedFd<'a>,
813 offs: off_t,
814 buf: &'a [u8],
815 prio: i32,
816 sigev_notify: SigevNotify,
817 ) -> Self {
818 let mut aiocb = AioCb::common_init(fd, prio, sigev_notify);
819 aiocb.aiocb.0.aio_nbytes = buf.len();
820 // casting an immutable buffer to a mutable pointer looks unsafe,
821 // but technically its only unsafe to dereference it, not to create
822 // it. Type Safety guarantees that we'll never pass aiocb to
823 // aio_read or aio_readv.
824 aiocb.aiocb.0.aio_buf = buf.as_ptr().cast_mut().cast();
825 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_WRITE;
826 aiocb.aiocb.0.aio_offset = offs;
827 AioWrite {
828 aiocb,
829 _data: PhantomData,
830 _pin: PhantomPinned,
831 }
832 }
833
834 /// Returns the file offset of the operation.
835 pub fn offset(&self) -> off_t {
836 self.aiocb.aiocb.0.aio_offset
837 }
838 }
839
840 impl<'a> Aio for AioWrite<'a> {
841 type Output = usize;
842
843 aio_methods!(aio_write);
844 }
845
846 impl AsMut<libc::aiocb> for AioWrite<'_> {
847 fn as_mut(&mut self) -> &mut libc::aiocb {
848 &mut self.aiocb.aiocb.0
849 }
850 }
851
852 impl AsRef<libc::aiocb> for AioWrite<'_> {
853 fn as_ref(&self) -> &libc::aiocb {
854 &self.aiocb.aiocb.0
855 }
856 }
857
858 /// Asynchronously writes from a scatter/gather list of buffers to a file descriptor.
859 ///
860 /// # References
861 ///
862 /// [aio_writev](https://www.freebsd.org/cgi/man.cgi?query=aio_writev)
863 ///
864 /// # Examples
865 ///
866 #[cfg_attr(fbsd14, doc = " ```")]
867 #[cfg_attr(not(fbsd14), doc = " ```no_run")]
868 /// # use nix::errno::Errno;
869 /// # use nix::Error;
870 /// # use nix::sys::aio::*;
871 /// # use nix::sys::signal::SigevNotify;
872 /// # use std::{thread, time};
873 /// # use std::io::IoSlice;
874 /// # use std::os::unix::io::AsFd;
875 /// # use tempfile::tempfile;
876 /// const wbuf0: &[u8] = b"abcdef";
877 /// const wbuf1: &[u8] = b"123456";
878 /// let len = wbuf0.len() + wbuf1.len();
879 /// let wbufs = [IoSlice::new(wbuf0), IoSlice::new(wbuf1)];
880 /// let mut f = tempfile().unwrap();
881 /// let mut aiow = Box::pin(
882 /// AioWritev::new(
883 /// f.as_fd(),
884 /// 2, //offset
885 /// &wbufs,
886 /// 0, //priority
887 /// SigevNotify::SigevNone
888 /// )
889 /// );
890 /// aiow.as_mut().submit().unwrap();
891 /// while (aiow.as_mut().error() == Err(Errno::EINPROGRESS)) {
892 /// thread::sleep(time::Duration::from_millis(10));
893 /// }
894 /// assert_eq!(aiow.as_mut().aio_return().unwrap(), len);
895 /// ```
896 #[cfg(target_os = "freebsd")]
897 #[derive(Debug)]
898 #[repr(transparent)]
899 pub struct AioWritev<'a> {
900 aiocb: AioCb<'a>,
901 _data: PhantomData<&'a [&'a [u8]]>,
902 _pin: PhantomPinned,
903 }
904
905 #[cfg(target_os = "freebsd")]
906 impl<'a> AioWritev<'a> {
907 unsafe_pinned!(aiocb: AioCb<'a>);
908
909 /// Returns the number of buffers the operation will read into.
910 pub fn iovlen(&self) -> usize {
911 self.aiocb.aiocb.0.aio_nbytes
912 }
913
914 /// Construct a new `AioWritev`.
915 ///
916 /// # Arguments
917 ///
918 /// * `fd`: File descriptor to write to
919 /// * `offs`: File offset
920 /// * `bufs`: A scatter/gather list of memory buffers. They must
921 /// outlive the `AioWritev`.
922 /// * `prio`: If POSIX Prioritized IO is supported, then the
923 /// operation will be prioritized at the process's
924 /// priority level minus `prio`
925 /// * `sigev_notify`: Determines how you will be notified of event
926 /// completion.
927 pub fn new(
928 fd: BorrowedFd<'a>,
929 offs: off_t,
930 bufs: &[IoSlice<'a>],
931 prio: i32,
932 sigev_notify: SigevNotify,
933 ) -> Self {
934 let mut aiocb = AioCb::common_init(fd, prio, sigev_notify);
935 // In vectored mode, aio_nbytes stores the length of the iovec array,
936 // not the byte count.
937 aiocb.aiocb.0.aio_nbytes = bufs.len();
938 // casting an immutable buffer to a mutable pointer looks unsafe,
939 // but technically its only unsafe to dereference it, not to create
940 // it. Type Safety guarantees that we'll never pass aiocb to
941 // aio_read or aio_readv.
942 aiocb.aiocb.0.aio_buf = bufs.as_ptr().cast_mut().cast();
943 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_WRITEV;
944 aiocb.aiocb.0.aio_offset = offs;
945 AioWritev {
946 aiocb,
947 _data: PhantomData,
948 _pin: PhantomPinned,
949 }
950 }
951
952 /// Returns the file offset of the operation.
953 pub fn offset(&self) -> off_t {
954 self.aiocb.aiocb.0.aio_offset
955 }
956 }
957
958 #[cfg(target_os = "freebsd")]
959 impl<'a> Aio for AioWritev<'a> {
960 type Output = usize;
961
962 aio_methods!(aio_writev);
963 }
964
965 #[cfg(target_os = "freebsd")]
966 impl AsMut<libc::aiocb> for AioWritev<'_> {
967 fn as_mut(&mut self) -> &mut libc::aiocb {
968 &mut self.aiocb.aiocb.0
969 }
970 }
971
972 #[cfg(target_os = "freebsd")]
973 impl AsRef<libc::aiocb> for AioWritev<'_> {
974 fn as_ref(&self) -> &libc::aiocb {
975 &self.aiocb.aiocb.0
976 }
977 }
978
979 /// Cancels outstanding AIO requests for a given file descriptor.
980 ///
981 /// # Examples
982 ///
983 /// Issue an aio operation, then cancel all outstanding operations on that file
984 /// descriptor.
985 ///
986 /// ```
987 /// # use nix::errno::Errno;
988 /// # use nix::Error;
989 /// # use nix::sys::aio::*;
990 /// # use nix::sys::signal::SigevNotify;
991 /// # use std::{thread, time};
992 /// # use std::io::Write;
993 /// # use std::os::unix::io::AsFd;
994 /// # use tempfile::tempfile;
995 /// let wbuf = b"CDEF";
996 /// let mut f = tempfile().unwrap();
997 /// let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
998 /// 2, //offset
999 /// &wbuf[..],
1000 /// 0, //priority
1001 /// SigevNotify::SigevNone));
1002 /// aiocb.as_mut().submit().unwrap();
1003 /// let cs = aio_cancel_all(f.as_fd()).unwrap();
1004 /// if cs == AioCancelStat::AioNotCanceled {
1005 /// while (aiocb.as_mut().error() == Err(Errno::EINPROGRESS)) {
1006 /// thread::sleep(time::Duration::from_millis(10));
1007 /// }
1008 /// }
1009 /// // Must call `aio_return`, but ignore the result
1010 /// let _ = aiocb.as_mut().aio_return();
1011 /// ```
1012 ///
1013 /// # References
1014 ///
1015 /// [`aio_cancel`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_cancel.html)
1016 pub fn aio_cancel_all<F: AsFd>(fd: F) -> Result<AioCancelStat> {
1017 match unsafe { libc::aio_cancel(fd.as_fd().as_raw_fd(), ptr::null_mut()) } {
1018 libc::AIO_CANCELED => Ok(AioCancelStat::AioCanceled),
1019 libc::AIO_NOTCANCELED => Ok(AioCancelStat::AioNotCanceled),
1020 libc::AIO_ALLDONE => Ok(AioCancelStat::AioAllDone),
1021 -1 => Err(Errno::last()),
1022 _ => panic!("unknown aio_cancel return value"),
1023 }
1024 }
1025
1026 /// Suspends the calling process until at least one of the specified operations
1027 /// have completed, a signal is delivered, or the timeout has passed.
1028 ///
1029 /// If `timeout` is `None`, `aio_suspend` will block indefinitely.
1030 ///
1031 /// # Examples
1032 ///
1033 /// Use `aio_suspend` to block until an aio operation completes.
1034 ///
1035 /// ```
1036 /// # use nix::sys::aio::*;
1037 /// # use nix::sys::signal::SigevNotify;
1038 /// # use std::os::unix::io::AsFd;
1039 /// # use tempfile::tempfile;
1040 /// const WBUF: &[u8] = b"abcdef123456";
1041 /// let mut f = tempfile().unwrap();
1042 /// let mut aiocb = Box::pin(AioWrite::new(f.as_fd(),
1043 /// 2, //offset
1044 /// WBUF,
1045 /// 0, //priority
1046 /// SigevNotify::SigevNone));
1047 /// aiocb.as_mut().submit().unwrap();
1048 /// aio_suspend(&[&*aiocb], None).expect("aio_suspend failed");
1049 /// assert_eq!(aiocb.as_mut().aio_return().unwrap(), WBUF.len());
1050 /// ```
1051 /// # References
1052 ///
1053 /// [`aio_suspend`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_suspend.html)
1054 pub fn aio_suspend(
1055 list: &[&dyn AsRef<libc::aiocb>],
1056 timeout: Option<TimeSpec>,
1057 ) -> Result<()> {
1058 // Note that this allocation could be eliminated by making the argument
1059 // generic, and accepting arguments like &[AioWrite]. But that would
1060 // prevent using aio_suspend to wait on a heterogeneous list of mixed
1061 // operations.
1062 let v = list
1063 .iter()
1064 .map(|x| x.as_ref() as *const libc::aiocb)
1065 .collect::<Vec<*const libc::aiocb>>();
1066 let p = v.as_ptr();
1067 let timep = match timeout {
1068 None => ptr::null::<libc::timespec>(),
1069 Some(x) => x.as_ref() as *const libc::timespec,
1070 };
1071 Errno::result(unsafe { libc::aio_suspend(p, list.len() as i32, timep) })
1072 .map(drop)
1073 }
1074
1075 /// Submits multiple asynchronous I/O requests with a single system call.
1076 ///
1077 /// They are not guaranteed to complete atomically, and the order in which the
1078 /// requests are carried out is not specified. Reads, and writes may be freely
1079 /// mixed.
1080 ///
1081 /// # Examples
1082 ///
1083 /// Use `lio_listio` to submit an aio operation and wait for its completion. In
1084 /// this case, there is no need to use aio_suspend to wait or `error` to poll.
1085 /// This mode is useful for otherwise-synchronous programs that want to execute
1086 /// a handful of I/O operations in parallel.
1087 /// ```
1088 /// # use std::os::unix::io::AsFd;
1089 /// # use nix::sys::aio::*;
1090 /// # use nix::sys::signal::SigevNotify;
1091 /// # use tempfile::tempfile;
1092 /// const WBUF: &[u8] = b"abcdef123456";
1093 /// let mut f = tempfile().unwrap();
1094 /// let mut aiow = Box::pin(AioWrite::new(
1095 /// f.as_fd(),
1096 /// 2, // offset
1097 /// WBUF,
1098 /// 0, // priority
1099 /// SigevNotify::SigevNone
1100 /// ));
1101 /// lio_listio(LioMode::LIO_WAIT, &mut[aiow.as_mut()], SigevNotify::SigevNone)
1102 /// .unwrap();
1103 /// // At this point, we are guaranteed that aiow is complete.
1104 /// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len());
1105 /// ```
1106 ///
1107 /// Use `lio_listio` to submit multiple asynchronous operations with a single
1108 /// syscall, but receive notification individually. This is an efficient
1109 /// technique for reducing overall context-switch overhead, especially when
1110 /// combined with kqueue.
1111 /// ```
1112 /// # use std::os::unix::io::AsFd;
1113 /// # use std::thread;
1114 /// # use std::time;
1115 /// # use nix::errno::Errno;
1116 /// # use nix::sys::aio::*;
1117 /// # use nix::sys::signal::SigevNotify;
1118 /// # use tempfile::tempfile;
1119 /// const WBUF: &[u8] = b"abcdef123456";
1120 /// let mut f = tempfile().unwrap();
1121 /// let mut aiow = Box::pin(AioWrite::new(
1122 /// f.as_fd(),
1123 /// 2, // offset
1124 /// WBUF,
1125 /// 0, // priority
1126 /// SigevNotify::SigevNone
1127 /// ));
1128 /// lio_listio(LioMode::LIO_NOWAIT, &mut[aiow.as_mut()], SigevNotify::SigevNone)
1129 /// .unwrap();
1130 /// // We must wait for the completion of each individual operation
1131 /// while (aiow.as_mut().error() == Err(Errno::EINPROGRESS)) {
1132 /// thread::sleep(time::Duration::from_millis(10));
1133 /// }
1134 /// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len());
1135 /// ```
1136 ///
1137 /// Use `lio_listio` to submit multiple operations, and receive notification
1138 /// only when all of them are complete. This can be useful when there is some
1139 /// logical relationship between the operations. But beware! Errors or system
1140 /// resource limitations may cause `lio_listio` to return `EIO`, `EAGAIN`, or
1141 /// `EINTR`, in which case some but not all operations may have been submitted.
1142 /// In that case, you must check the status of each individual operation, and
1143 /// possibly resubmit some.
1144 ///
1145 // Do not run this doc test on:
1146 // * aarch64-unknown-linux-musl
1147 // * i686-unknown-linux-musl
1148 // * x86_64-unknown-linux-musl
1149 // because it hangs on these targets. After further debugging, we think this is
1150 // likely a bug of musl. Since we only test our bindings and do not intend to
1151 // fix the underlying libc bug, we skip this test here.
1152 // See this thread for the discussion of this issue:
1153 // 1. https://github.com/nix-rust/nix/pull/2689#issuecomment-3419813159
1154 // 2. https://github.com/nix-rust/nix/issues/2788
1155 #[cfg_attr(
1156 all(
1157 target_env = "musl",
1158 any(
1159 target_arch = "aarch64",
1160 target_arch = "x86",
1161 target_arch = "x86_64"
1162 )
1163 ),
1164 doc = " ```no_run"
1165 )]
1166 #[cfg_attr(
1167 not(all(
1168 target_env = "musl",
1169 any(
1170 target_arch = "aarch64",
1171 target_arch = "x86",
1172 target_arch = "x86_64"
1173 )
1174 )),
1175 doc = " ```"
1176 )]
1177 /// # use libc::c_int;
1178 /// # use std::os::unix::io::AsFd;
1179 /// # use std::sync::atomic::{AtomicBool, Ordering};
1180 /// # use std::thread;
1181 /// # use std::time;
1182 /// # use nix::errno::Errno;
1183 /// # use nix::sys::aio::*;
1184 /// # use nix::sys::signal::*;
1185 /// # use tempfile::tempfile;
1186 /// pub static SIGNALED: AtomicBool = AtomicBool::new(false);
1187 ///
1188 /// extern fn sigfunc(_: c_int) {
1189 /// SIGNALED.store(true, Ordering::Relaxed);
1190 /// }
1191 /// let sa = SigAction::new(SigHandler::Handler(sigfunc),
1192 /// SaFlags::SA_RESETHAND,
1193 /// SigSet::empty());
1194 /// SIGNALED.store(false, Ordering::Relaxed);
1195 /// unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
1196 ///
1197 /// const WBUF: &[u8] = b"abcdef123456";
1198 /// let mut f = tempfile().unwrap();
1199 /// let mut aiow = Box::pin(AioWrite::new(
1200 /// f.as_fd(),
1201 /// 2, // offset
1202 /// WBUF,
1203 /// 0, // priority
1204 /// SigevNotify::SigevNone
1205 /// ));
1206 /// let sev = SigevNotify::SigevSignal { signal: Signal::SIGUSR2, si_value: 0 };
1207 /// lio_listio(LioMode::LIO_NOWAIT, &mut[aiow.as_mut()], sev).unwrap();
1208 /// while !SIGNALED.load(Ordering::Relaxed) {
1209 /// thread::sleep(time::Duration::from_millis(10));
1210 /// }
1211 /// // At this point, since `lio_listio` returned success and delivered its
1212 /// // notification, we know that all operations are complete.
1213 /// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len());
1214 /// ```
1215 #[deprecated(
1216 since = "0.27.0",
1217 note = "https://github.com/nix-rust/nix/issues/2017"
1218 )]
1219 pub fn lio_listio(
1220 mode: LioMode,
1221 list: &mut [Pin<&mut dyn AsMut<libc::aiocb>>],
1222 sigev_notify: SigevNotify,
1223 ) -> Result<()> {
1224 let p = list as *mut [Pin<&mut dyn AsMut<libc::aiocb>>]
1225 as *mut [*mut libc::aiocb] as *mut *mut libc::aiocb;
1226 let sigev = SigEvent::new(sigev_notify);
1227 let sigevp = &mut sigev.sigevent() as *mut libc::sigevent;
1228 Errno::result(unsafe {
1229 libc::lio_listio(mode as i32, p, list.len() as i32, sigevp)
1230 })
1231 .map(drop)
1232 }