Lines Matching +full:use +full:- +full:libc
4 //! The POSIX AIO interface is used for asynchronous I/O on files and disk-like
27 use std::io::{IoSlice, IoSliceMut};
28 use std::{
38 use libc::{c_void, off_t};
39 use pin_utils::unsafe_pinned;
41 use crate::{
85 AioCanceled = libc::AIO_CANCELED,
88 AioNotCanceled = libc::AIO_NOTCANCELED,
90 AioAllDone = libc::AIO_ALLDONE,
93 /// Newtype that adds Send and Sync to libc::aiocb, which contains raw pointers
95 struct LibcAiocb(libc::aiocb);
110 /// Could this `AioCb` potentially have any in-kernel state?
111 // It would be really nice to perform the in-progress check entirely at
123 fn aio_return(mut self: Pin<&mut Self>) -> Result<usize> { in aio_return()
126 let p: *mut libc::aiocb = &mut self.aiocb.0; in aio_return()
127 Errno::result(libc::aio_return(p)) in aio_return()
132 fn cancel(mut self: Pin<&mut Self>) -> Result<AioCancelStat> { in cancel()
134 libc::aio_cancel(self.aiocb.0.aio_fildes, &mut self.aiocb.0) in cancel()
137 libc::AIO_CANCELED => Ok(AioCancelStat::AioCanceled), in cancel()
138 libc::AIO_NOTCANCELED => Ok(AioCancelStat::AioNotCanceled), in cancel()
139 libc::AIO_ALLDONE => Ok(AioCancelStat::AioAllDone), in cancel()
140 -1 => Err(Errno::last()), in cancel()
145 fn common_init(fd: RawFd, prio: i32, sigev_notify: SigevNotify) -> Self { in common_init()
146 // Use mem::zeroed instead of explicitly zeroing each field, because the in common_init()
147 // number and name of reserved fields is OS-dependent. On some OSes, in common_init()
150 let mut a = unsafe { mem::zeroed::<libc::aiocb>() }; in common_init()
160 fn error(self: Pin<&mut Self>) -> Result<()> { in error()
161 let r = unsafe { libc::aio_error(&self.aiocb().0) }; in error()
165 -1 => Err(Errno::last()), in error()
170 fn in_progress(&self) -> bool { in in_progress()
186 "Can't change notification settings for an in-progress operation" in set_sigev_notify()
193 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { in fmt()
207 "Dropped an in-progress AioCb" in drop()
226 fn aio_return(self: Pin<&mut Self>) -> Result<Self::Output>; in aio_return()
243 /// # use nix::errno::Errno;
244 /// # use nix::Error;
245 /// # use nix::sys::aio::*;
246 /// # use nix::sys::signal::SigevNotify;
247 /// # use std::{thread, time};
248 /// # use std::io::Write;
249 /// # use std::os::unix::io::AsRawFd;
250 /// # use tempfile::tempfile;
272 fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat>; in cancel()
281 /// Issue an aio operation and use `error` to poll for completion. Polling
285 /// # use nix::errno::Errno;
286 /// # use nix::Error;
287 /// # use nix::sys::aio::*;
288 /// # use nix::sys::signal::SigevNotify;
289 /// # use std::{thread, time};
290 /// # use std::os::unix::io::AsRawFd;
291 /// # use tempfile::tempfile;
309 fn error(self: Pin<&mut Self>) -> Result<()>; in error()
312 fn fd(&self) -> RawFd; in fd()
314 /// Does this operation currently have any in-kernel state?
316 /// Dropping an operation that does have in-kernel state constitutes a
322 /// # use nix::errno::Errno;
323 /// # use nix::Error;
324 /// # use nix::sys::aio::*;
325 /// # use nix::sys::signal::SigevNotify::SigevNone;
326 /// # use std::{thread, time};
327 /// # use std::os::unix::io::AsRawFd;
328 /// # use tempfile::tempfile;
341 fn in_progress(&self) -> bool; in in_progress()
344 fn priority(&self) -> i32; in priority()
351 fn sigevent(&self) -> SigEvent; in sigevent()
357 fn submit(self: Pin<&mut Self>) -> Result<()>; in submit()
362 fn cancel(self: Pin<&mut Self>) -> Result<AioCancelStat> {
366 fn error(self: Pin<&mut Self>) -> Result<()> {
370 fn fd(&self) -> RawFd {
374 fn in_progress(&self) -> bool {
378 fn priority(&self) -> i32 {
386 fn sigevent(&self) -> SigEvent {
393 fn aio_return(self: Pin<&mut Self>) -> Result<<Self as Aio>::Output> {
397 fn submit(mut self: Pin<&mut Self>) -> Result<()> {
398 let p: *mut libc::aiocb = &mut self.as_mut().aiocb().aiocb.0;
399 Errno::result({ unsafe { libc::$func(p) } }).map(|_| {
414 /// # use nix::errno::Errno;
415 /// # use nix::Error;
416 /// # use nix::sys::aio::*;
417 /// # use nix::sys::signal::SigevNotify::SigevNone;
418 /// # use std::{thread, time};
419 /// # use std::os::unix::io::AsRawFd;
420 /// # use tempfile::tempfile;
441 pub fn mode(&self) -> AioFsyncMode { in mode()
461 ) -> Self { in new()
467 aiocb.aiocb.0.aio_lio_opcode = mode as libc::c_int; in new()
480 fn aio_return(self: Pin<&mut Self>) -> Result<()> { in aio_return()
484 fn submit(mut self: Pin<&mut Self>) -> Result<()> { in submit()
487 let p: *mut libc::aiocb = aiocb; in submit()
488 Errno::result(unsafe { libc::aio_fsync(mode, p) }).map(|_| { in submit()
496 impl AsRef<libc::aiocb> for AioFsync {
497 fn as_ref(&self) -> &libc::aiocb { in as_ref()
512 /// # use nix::errno::Errno;
513 /// # use nix::Error;
514 /// # use nix::sys::aio::*;
515 /// # use nix::sys::signal::SigevNotify;
516 /// # use std::{thread, time};
517 /// # use std::io::Write;
518 /// # use std::os::unix::io::AsRawFd;
519 /// # use tempfile::tempfile;
557 /// number of bytes actually read or written by a completed operation, use
559 pub fn nbytes(&self) -> usize { in nbytes()
581 ) -> Self { in new()
585 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_READ; in new()
595 pub fn offset(&self) -> off_t { in offset()
606 impl<'a> AsMut<libc::aiocb> for AioRead<'a> {
607 fn as_mut(&mut self) -> &mut libc::aiocb { in as_mut()
612 impl<'a> AsRef<libc::aiocb> for AioRead<'a> {
613 fn as_ref(&self) -> &libc::aiocb { in as_ref()
629 /// # use nix::errno::Errno;
630 /// # use nix::Error;
631 /// # use nix::sys::aio::*;
632 /// # use nix::sys::signal::SigevNotify;
633 /// # use std::{thread, time};
634 /// # use std::io::{IoSliceMut, Write};
635 /// # use std::os::unix::io::AsRawFd;
636 /// # use tempfile::tempfile;
677 pub fn iovlen(&self) -> usize { in iovlen()
700 ) -> Self { in new()
706 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_READV; in new()
716 pub fn offset(&self) -> off_t { in offset()
729 impl<'a> AsMut<libc::aiocb> for AioReadv<'a> {
730 fn as_mut(&mut self) -> &mut libc::aiocb { in as_mut()
736 impl<'a> AsRef<libc::aiocb> for AioReadv<'a> {
737 fn as_ref(&self) -> &libc::aiocb { in as_ref()
751 /// # use nix::errno::Errno;
752 /// # use nix::Error;
753 /// # use nix::sys::aio::*;
754 /// # use nix::sys::signal::SigevNotify;
755 /// # use std::{thread, time};
756 /// # use std::os::unix::io::AsRawFd;
757 /// # use tempfile::tempfile;
789 /// number of bytes actually read or written by a completed operation, use
791 pub fn nbytes(&self) -> usize { in nbytes()
813 ) -> Self { in new()
821 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_WRITE; in new()
831 pub fn offset(&self) -> off_t { in offset()
842 impl<'a> AsMut<libc::aiocb> for AioWrite<'a> {
843 fn as_mut(&mut self) -> &mut libc::aiocb { in as_mut()
848 impl<'a> AsRef<libc::aiocb> for AioWrite<'a> {
849 fn as_ref(&self) -> &libc::aiocb { in as_ref()
864 /// # use nix::errno::Errno;
865 /// # use nix::Error;
866 /// # use nix::sys::aio::*;
867 /// # use nix::sys::signal::SigevNotify;
868 /// # use std::{thread, time};
869 /// # use std::io::IoSlice;
870 /// # use std::os::unix::io::AsRawFd;
871 /// # use tempfile::tempfile;
906 pub fn iovlen(&self) -> usize { in iovlen()
929 ) -> Self { in new()
939 aiocb.aiocb.0.aio_lio_opcode = libc::LIO_WRITEV; in new()
949 pub fn offset(&self) -> off_t { in offset()
962 impl<'a> AsMut<libc::aiocb> for AioWritev<'a> {
963 fn as_mut(&mut self) -> &mut libc::aiocb { in as_mut()
969 impl<'a> AsRef<libc::aiocb> for AioWritev<'a> {
970 fn as_ref(&self) -> &libc::aiocb { in as_ref()
983 /// # use nix::errno::Errno;
984 /// # use nix::Error;
985 /// # use nix::sys::aio::*;
986 /// # use nix::sys::signal::SigevNotify;
987 /// # use std::{thread, time};
988 /// # use std::io::Write;
989 /// # use std::os::unix::io::AsRawFd;
990 /// # use tempfile::tempfile;
1012 pub fn aio_cancel_all(fd: RawFd) -> Result<AioCancelStat> { in aio_cancel_all()
1013 match unsafe { libc::aio_cancel(fd, ptr::null_mut()) } { in aio_cancel_all()
1014 libc::AIO_CANCELED => Ok(AioCancelStat::AioCanceled), in aio_cancel_all()
1015 libc::AIO_NOTCANCELED => Ok(AioCancelStat::AioNotCanceled), in aio_cancel_all()
1016 libc::AIO_ALLDONE => Ok(AioCancelStat::AioAllDone), in aio_cancel_all()
1017 -1 => Err(Errno::last()), in aio_cancel_all()
1029 /// Use `aio_suspend` to block until an aio operation completes.
1032 /// # use nix::sys::aio::*;
1033 /// # use nix::sys::signal::SigevNotify;
1034 /// # use std::os::unix::io::AsRawFd;
1035 /// # use tempfile::tempfile;
1051 list: &[&dyn AsRef<libc::aiocb>], in aio_suspend()
1053 ) -> Result<()> { in aio_suspend()
1054 let p = list as *const [&dyn AsRef<libc::aiocb>] in aio_suspend()
1055 as *const [*const libc::aiocb] as *const *const libc::aiocb; in aio_suspend() constant
1057 None => ptr::null::<libc::timespec>(), in aio_suspend()
1058 Some(x) => x.as_ref() as *const libc::timespec, in aio_suspend() constant
1060 Errno::result(unsafe { libc::aio_suspend(p, list.len() as i32, timep) }) in aio_suspend()
1072 /// Use `lio_listio` to submit an aio operation and wait for its completion. In
1073 /// this case, there is no need to use aio_suspend to wait or `error` to poll.
1074 /// This mode is useful for otherwise-synchronous programs that want to execute
1077 /// # use std::os::unix::io::AsRawFd;
1078 /// # use nix::sys::aio::*;
1079 /// # use nix::sys::signal::SigevNotify;
1080 /// # use tempfile::tempfile;
1096 /// Use `lio_listio` to submit multiple asynchronous operations with a single
1098 /// technique for reducing overall context-switch overhead, especially when
1101 /// # use std::os::unix::io::AsRawFd;
1102 /// # use std::thread;
1103 /// # use std::time;
1104 /// # use nix::errno::Errno;
1105 /// # use nix::sys::aio::*;
1106 /// # use nix::sys::signal::SigevNotify;
1107 /// # use tempfile::tempfile;
1126 /// Use `lio_listio` to submit multiple operations, and receive notification
1134 /// # use libc::c_int;
1135 /// # use std::os::unix::io::AsRawFd;
1136 /// # use std::sync::atomic::{AtomicBool, Ordering};
1137 /// # use std::thread;
1138 /// # use std::time;
1139 /// # use lazy_static::lazy_static;
1140 /// # use nix::errno::Errno;
1141 /// # use nix::sys::aio::*;
1142 /// # use nix::sys::signal::*;
1143 /// # use tempfile::tempfile;
1177 list: &mut [Pin<&mut dyn AsMut<libc::aiocb>>], in lio_listio()
1179 ) -> Result<()> { in lio_listio()
1180 let p = list as *mut [Pin<&mut dyn AsMut<libc::aiocb>>] in lio_listio()
1181 as *mut [*mut libc::aiocb] as *mut *mut libc::aiocb; in lio_listio()
1183 let sigevp = &mut sigev.sigevent() as *mut libc::sigevent; in lio_listio()
1185 libc::lio_listio(mode as i32, p, list.len() as i32, sigevp) in lio_listio()
1192 use super::*;
1194 /// aio_suspend relies on casting Rust Aio* struct pointers to libc::aiocb
1201 aiof.as_ref() as *const libc::aiocb, in casting()
1202 &aiof as *const AioFsync as *const libc::aiocb in casting()
1208 aior.as_ref() as *const libc::aiocb, in casting()
1209 &aior as *const AioRead as *const libc::aiocb in casting()
1215 aiow.as_ref() as *const libc::aiocb, in casting()
1216 &aiow as *const AioWrite as *const libc::aiocb in casting()
1229 aiorv.as_ref() as *const libc::aiocb, in casting_vectored()
1230 &aiorv as *const AioReadv as *const libc::aiocb in casting_vectored()
1237 aiowv.as_ref() as *const libc::aiocb, in casting_vectored()
1238 &aiowv as *const AioWritev as *const libc::aiocb in casting_vectored()