diff --git a/src/imp/libc/fs/types.rs b/src/imp/libc/fs/types.rs index d77506430..c1f03a68b 100644 --- a/src/imp/libc/fs/types.rs +++ b/src/imp/libc/fs/types.rs @@ -741,15 +741,20 @@ pub type FsWord = u32; #[cfg(not(target_os = "redox"))] pub use c::{UTIME_NOW, UTIME_OMIT}; +/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem. #[cfg(all( any(target_os = "android", target_os = "linux"), not(target_env = "musl") ))] pub const PROC_SUPER_MAGIC: FsWord = c::PROC_SUPER_MAGIC as FsWord; +/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem. #[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))] pub const PROC_SUPER_MAGIC: FsWord = 0x0000_9fa0; +/// `copyfile_state_t`—State for use with [`fcopyfile`]. +/// +/// [`fcopyfile`]: crate::fs::fcopyfile #[cfg(any(target_os = "ios", target_os = "macos"))] #[allow(non_camel_case_types)] #[repr(transparent)] diff --git a/src/imp/libc/io/epoll.rs b/src/imp/libc/io/epoll.rs index 9171ddc0c..76a805529 100644 --- a/src/imp/libc/io/epoll.rs +++ b/src/imp/libc/io/epoll.rs @@ -54,6 +54,8 @@ //! # } //! ``` +#![allow(missing_docs)] // TODO: Write more docs. + use super::super::c; use super::super::conv::{ret, ret_owned_fd, ret_u32}; use super::super::fd::{AsFd, AsRawFd, BorrowedFd, RawFd}; diff --git a/src/imp/libc/io/error.rs b/src/imp/libc/io/error.rs index 29c288a83..3fdf30e1e 100644 --- a/src/imp/libc/io/error.rs +++ b/src/imp/libc/io/error.rs @@ -3,6 +3,8 @@ //! This type holds an OS error code, which conceptually corresponds to an //! `errno` value. +#![allow(missing_docs)] + use super::super::c; use errno::errno; diff --git a/src/imp/libc/io/poll_fd.rs b/src/imp/libc/io/poll_fd.rs index 51b873017..5b08ee29c 100644 --- a/src/imp/libc/io/poll_fd.rs +++ b/src/imp/libc/io/poll_fd.rs @@ -5,7 +5,9 @@ use bitflags::bitflags; use core::marker::PhantomData; bitflags! { - /// `POLL*` + /// `POLL*` flags for use with [`poll`]. + /// + /// [`poll`]: rustix::io::poll pub struct PollFlags: c::c_short { /// `POLLIN` const IN = c::POLLIN; @@ -41,7 +43,10 @@ bitflags! { } } -/// `struct pollfd` +/// `struct pollfd`—File descriptor and flags for use with [`poll`]. +/// +/// [`poll`]: rustix::io::poll +#[doc(alias = "pollfd")] #[derive(Clone, Debug)] #[repr(transparent)] pub struct PollFd<'fd> { diff --git a/src/imp/libc/io/types.rs b/src/imp/libc/io/types.rs index a1495fe68..25dda720d 100644 --- a/src/imp/libc/io/types.rs +++ b/src/imp/libc/io/types.rs @@ -9,19 +9,19 @@ bitflags! { /// [`preadv2`]: crate::io::preadv2 /// [`pwritev2`]: crate::io::pwritev pub struct ReadWriteFlags: c::c_int { - /// `RWF_DSYNC` + /// `RWF_DSYNC` (since Linux 4.7) #[cfg(all(target_os = "linux", target_env = "gnu"))] const DSYNC = c::RWF_DSYNC; - /// `RWF_HIPRI` + /// `RWF_HIPRI` (since Linux 4.6) #[cfg(all(target_os = "linux", target_env = "gnu"))] const HIPRI = c::RWF_HIPRI; - /// `RWF_SYNC` + /// `RWF_SYNC` (since Linux 4.7) #[cfg(all(target_os = "linux", target_env = "gnu"))] const SYNC = c::RWF_SYNC; - /// `RWF_NOWAIT` + /// `RWF_NOWAIT` (since Linux 4.14) #[cfg(all(target_os = "linux", target_env = "gnu"))] const NOWAIT = c::RWF_NOWAIT; - /// `RWF_APPEND` + /// `RWF_APPEND` (since Linux 4.16) #[cfg(all(target_os = "linux", target_env = "gnu"))] const APPEND = c::RWF_APPEND; } @@ -429,11 +429,15 @@ pub type Termios = c::termios; #[cfg(not(target_os = "wasi"))] pub type Winsize = c::winsize; +/// `tcflag_t`—A type for the flags fields of [`Termios`]. #[cfg(not(target_os = "wasi"))] pub type Tcflag = c::tcflag_t; +/// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating +/// canonical mode. #[cfg(not(target_os = "wasi"))] pub const ICANON: Tcflag = c::ICANON; +/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic. #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub const PIPE_BUF: usize = c::PIPE_BUF; diff --git a/src/imp/libc/io_lifetimes.rs b/src/imp/libc/io_lifetimes.rs index acc25741f..8e2ead979 100644 --- a/src/imp/libc/io_lifetimes.rs +++ b/src/imp/libc/io_lifetimes.rs @@ -9,7 +9,13 @@ pub(crate) use io_lifetimes::OwnedSocket as OwnedFd; pub use std::os::windows::io::RawSocket as RawFd; pub(crate) use winapi::um::winsock2::SOCKET as LibcFd; +/// A version of [`AsRawFd`] for use with Winsock APIs. +/// +/// [`AsRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsRawFd.html pub trait AsRawFd { + /// A version of [`as_raw_fd`] for use with Winsock APIs. + /// + /// [`as_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.as_raw_fd fn as_raw_fd(&self) -> RawFd; } #[cfg(feature = "std")] @@ -20,7 +26,13 @@ impl AsRawFd for T { } } +/// A version of [`IntoRawFd`] for use with Winsock APIs. +/// +/// [`IntoRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.IntoRawFd.html pub trait IntoRawFd { + /// A version of [`into_raw_fd`] for use with Winsock APIs. + /// + /// [`into_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.into_raw_fd fn into_raw_fd(self) -> RawFd; } #[cfg(feature = "std")] @@ -31,7 +43,13 @@ impl IntoRawFd for T { } } +/// A version of [`FromRawFd`] for use with Winsock APIs. +/// +/// [`FromRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html pub trait FromRawFd { + /// A version of [`from_raw_fd`] for use with Winsock APIs. + /// + /// [`from_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd unsafe fn from_raw_fd(raw_fd: RawFd) -> Self; } #[cfg(feature = "std")] @@ -42,6 +60,9 @@ impl FromRawFd for T { } } +/// A version of [`AsFd`] for use with Winsock APIs. +/// +/// [`AsFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsFd.html pub use io_lifetimes::AsSocket as AsFd; /// We define `AsFd` as an alias for `AsSocket`, but that doesn't provide @@ -57,7 +78,13 @@ impl AsSocketAsFd for T { } } +/// A version of [`IntoFd`] for use with Winsock APIs. +/// +/// [`IntoFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html pub trait IntoFd { + /// A version of [`into_fd`] for use with Winsock APIs. + /// + /// [`into_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html#tymethod.into_fd fn into_fd(self) -> OwnedFd; } impl IntoFd for T { @@ -67,7 +94,13 @@ impl IntoFd for T { } } +/// A version of [`FromFd`] for use with Winsock APIs. +/// +/// [`FromFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html pub trait FromFd { + /// A version of [`from_fd`] for use with Winsock APIs. + /// + /// [`from_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html#tymethod.from_fd fn from_fd(fd: OwnedFd) -> Self; } impl FromFd for T { diff --git a/src/imp/libc/net/types.rs b/src/imp/libc/net/types.rs index c8b31fe08..77b050328 100644 --- a/src/imp/libc/net/types.rs +++ b/src/imp/libc/net/types.rs @@ -5,7 +5,7 @@ use bitflags::bitflags; #[doc(hidden)] pub type RawSocketType = u32; -/// `SOCK_*` constants for [`socket`]. +/// `SOCK_*` constants for use with [`socket`]. /// /// [`socket`]: crate::net::socket #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] @@ -505,22 +505,22 @@ impl Protocol { } } -/// `SHUT_*` constants for [`shutdown`]. +/// `SHUT_*` constants for use with [`shutdown`]. /// /// [`shutdown`]: crate::net::shutdown #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[repr(i32)] pub enum Shutdown { - /// `SHUT_RD` + /// `SHUT_RD`—Disable further read operations. Read = c::SHUT_RD, - /// `SHUT_WR` + /// `SHUT_WR`—Disable further write operations. Write = c::SHUT_WR, - /// `SHUT_RDWR` + /// `SHUT_RDWR`—Disable further read and write operations. ReadWrite = c::SHUT_RDWR, } bitflags! { - /// `SOCK_*` constants for [`accept_with`] and [`acceptfrom_with`]. + /// `SOCK_*` constants for use with [`accept_with`] and [`acceptfrom_with`]. /// /// [`accept_with`]: crate::net::accept_with /// [`acceptfrom_with`]: crate::net::acceptfrom_with @@ -536,7 +536,7 @@ bitflags! { } bitflags! { - /// `SOCK_*` constants for [`socket`]. + /// `SOCK_*` constants for use with [`socket`]. /// /// [`socket`]: crate::net::socket pub struct SocketFlags: c::c_int { diff --git a/src/imp/libc/process/mod.rs b/src/imp/libc/process/mod.rs index 4e5f9c5f8..bf101ee63 100644 --- a/src/imp/libc/process/mod.rs +++ b/src/imp/libc/process/mod.rs @@ -23,6 +23,8 @@ pub(crate) use c::{ target_os = "dragonfly" ))] pub(crate) mod cpu_set; +#[cfg(not(target_os = "wasi"))] +pub(crate) use types::RawUname; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] pub use types::Resource; #[cfg(any( @@ -35,5 +37,5 @@ pub(crate) use types::{raw_cpu_set_new, RawCpuSet, CPU_SETSIZE}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use types::{MembarrierCommand, RawCpuid}; #[cfg(not(target_os = "wasi"))] -pub use types::{RawGid, RawPid, RawUid, RawUname, EXIT_SIGNALED_SIGABRT}; +pub use types::{RawGid, RawPid, RawUid, EXIT_SIGNALED_SIGABRT}; pub use types::{EXIT_FAILURE, EXIT_SUCCESS}; diff --git a/src/imp/libc/process/types.rs b/src/imp/libc/process/types.rs index 38d30dd6b..4549dce30 100644 --- a/src/imp/libc/process/types.rs +++ b/src/imp/libc/process/types.rs @@ -140,17 +140,21 @@ pub const EXIT_FAILURE: c::c_int = c::EXIT_FAILURE; #[cfg(not(target_os = "wasi"))] pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT; +/// A process identifier as a raw integer. #[cfg(not(target_os = "wasi"))] pub type RawPid = c::pid_t; +/// A group identifier as a raw integer. #[cfg(not(target_os = "wasi"))] pub type RawGid = c::gid_t; +/// A user identifier as a raw integer. #[cfg(not(target_os = "wasi"))] pub type RawUid = c::uid_t; +/// A CPU identifier as a raw integer. #[cfg(any(target_os = "android", target_os = "linux"))] pub type RawCpuid = u32; #[cfg(not(target_os = "wasi"))] -pub type RawUname = c::utsname; +pub(crate) type RawUname = c::utsname; #[cfg(any( target_os = "linux", diff --git a/src/imp/libc/rand/types.rs b/src/imp/libc/rand/types.rs index 608dd425c..c035431cc 100644 --- a/src/imp/libc/rand/types.rs +++ b/src/imp/libc/rand/types.rs @@ -5,10 +5,13 @@ use bitflags::bitflags; #[cfg(target_os = "linux")] bitflags! { + /// `GRND_*` flags for use with [`getrandom`]. + /// + /// [`getrandom`]: crate::rand::getrandom pub struct GetRandomFlags: u32 { - /// GRND_RANDOM + /// `GRND_RANDOM` const RANDOM = c::GRND_RANDOM; - /// GRND_NONBLOCK + /// `GRND_NONBLOCK` const NONBLOCK = c::GRND_NONBLOCK; } } diff --git a/src/imp/libc/time/types.rs b/src/imp/libc/time/types.rs index b7650e013..9297e4625 100644 --- a/src/imp/libc/time/types.rs +++ b/src/imp/libc/time/types.rs @@ -5,10 +5,15 @@ use super::super::fd::BorrowedFd; /// `struct timespec` pub type Timespec = c::timespec; +/// A type for the `tv_sec` field of [`Timespec`]. #[allow(deprecated)] pub type Secs = c::time_t; + +/// A type for the `tv_nsec` field of [`Timespec`]. #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] pub type Nsecs = i64; + +/// A type for the `tv_nsec` field of [`Timespec`]. #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] pub type Nsecs = c::c_long; diff --git a/src/imp/linux_raw/conv.rs b/src/imp/linux_raw/conv.rs index 5f069bf58..9d10ff0a0 100644 --- a/src/imp/linux_raw/conv.rs +++ b/src/imp/linux_raw/conv.rs @@ -33,6 +33,7 @@ use linux_raw_sys::general::{__kernel_clockid_t, socklen_t}; /// Convert `SYS_*` constants for socketcall. #[cfg(target_arch = "x86")] +#[inline] pub(super) fn x86_sys<'a, Num: ArgNumber>(sys: u32) -> ArgReg<'a, Num> { raw_arg(sys as usize) } @@ -233,6 +234,7 @@ pub(super) fn dev_t<'a, Num: ArgNumber>(dev: u64) -> io::Result> } #[cfg(target_pointer_width = "32")] +#[inline] fn oflags_bits(oflags: OFlags) -> c::c_uint { let mut bits = oflags.bits(); // Add `O_LARGEFILE`, unless `O_PATH` is set, as Linux returns `EINVAL` @@ -244,14 +246,17 @@ fn oflags_bits(oflags: OFlags) -> c::c_uint { } #[cfg(target_pointer_width = "64")] +#[inline] fn oflags_bits(oflags: OFlags) -> c::c_uint { oflags.bits() } +#[inline] pub(super) fn oflags<'a, Num: ArgNumber>(oflags: OFlags) -> ArgReg<'a, Num> { raw_arg(oflags_bits(oflags) as usize) } +#[inline] pub(super) fn oflags_for_open_how(oflags: OFlags) -> u64 { u64::from(oflags_bits(oflags)) } diff --git a/src/imp/linux_raw/fs/types.rs b/src/imp/linux_raw/fs/types.rs index 8d336f52e..6979ccbd9 100644 --- a/src/imp/linux_raw/fs/types.rs +++ b/src/imp/linux_raw/fs/types.rs @@ -512,4 +512,5 @@ pub type FsWord = linux_raw_sys::general::__fsword_t; pub use linux_raw_sys::general::{UTIME_NOW, UTIME_OMIT}; +/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem. pub const PROC_SUPER_MAGIC: FsWord = linux_raw_sys::general::PROC_SUPER_MAGIC as FsWord; diff --git a/src/imp/linux_raw/io/epoll.rs b/src/imp/linux_raw/io/epoll.rs index a96eb9b5d..6e8f0949b 100644 --- a/src/imp/linux_raw/io/epoll.rs +++ b/src/imp/linux_raw/io/epoll.rs @@ -55,6 +55,7 @@ //! ``` #![allow(unsafe_code)] +#![allow(missing_docs)] // TODO: Write more docs. use super::super::c; use crate::fd::{AsFd, AsRawFd, BorrowedFd, RawFd}; diff --git a/src/imp/linux_raw/io/error.rs b/src/imp/linux_raw/io/error.rs index 50c2bc36f..1403608d3 100644 --- a/src/imp/linux_raw/io/error.rs +++ b/src/imp/linux_raw/io/error.rs @@ -8,6 +8,7 @@ //! Linux uses error codes in `-4095..0`; we use rustc attributes to describe //! this restricted range of values. #![allow(unsafe_code)] +#![allow(missing_docs)] #![cfg_attr(not(rustc_attrs), allow(unused_unsafe))] use super::super::c; diff --git a/src/imp/linux_raw/io/poll_fd.rs b/src/imp/linux_raw/io/poll_fd.rs index 5aa8fc141..cb466ba0a 100644 --- a/src/imp/linux_raw/io/poll_fd.rs +++ b/src/imp/linux_raw/io/poll_fd.rs @@ -2,7 +2,9 @@ use super::super::fd::{AsFd, BorrowedFd}; use bitflags::bitflags; bitflags! { - /// `POLL*` + /// `POLL*` flags for use with [`poll`]. + /// + /// [`poll`]: rustix::io::poll pub struct PollFlags: u16 { /// `POLLIN` const IN = linux_raw_sys::general::POLLIN as u16; @@ -29,7 +31,10 @@ bitflags! { } } -/// `struct pollfd` +/// `struct pollfd`—File descriptor and flags for use with [`poll`]. +/// +/// [`poll`]: rustix::io::poll +#[doc(alias = "pollfd")] #[repr(C)] #[derive(Debug, Clone)] pub struct PollFd<'fd> { diff --git a/src/imp/linux_raw/io/types.rs b/src/imp/linux_raw/io/types.rs index 6bef14672..43494e00a 100644 --- a/src/imp/linux_raw/io/types.rs +++ b/src/imp/linux_raw/io/types.rs @@ -7,15 +7,15 @@ bitflags! { /// [`preadv2`]: crate::io::preadv2 /// [`pwritev2`]: crate::io::pwritev pub struct ReadWriteFlags: c::c_uint { - /// `RWF_DSYNC` + /// `RWF_DSYNC` (since Linux 4.7) const DSYNC = linux_raw_sys::general::RWF_DSYNC; - /// `RWF_HIPRI` + /// `RWF_HIPRI` (since Linux 4.6) const HIPRI = linux_raw_sys::general::RWF_HIPRI; - /// `RWF_SYNC` + /// `RWF_SYNC` (since Linux 4.7) const SYNC = linux_raw_sys::general::RWF_SYNC; - /// `RWF_NOWAIT` + /// `RWF_NOWAIT` (since Linux 4.14) const NOWAIT = linux_raw_sys::general::RWF_NOWAIT; - /// `RWF_APPEND` + /// `RWF_APPEND` (since Linux 4.16) const APPEND = linux_raw_sys::general::RWF_APPEND; } } @@ -249,8 +249,12 @@ pub type Termios = linux_raw_sys::general::termios; /// [`ioctl_tiocgwinsz`]: crate::io::ioctl_tiocgwinsz pub type Winsize = linux_raw_sys::general::winsize; +/// `tcflag_t`—A type for the flags fields of [`Termios`]. pub type Tcflag = linux_raw_sys::general::tcflag_t; +/// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating +/// canonical mode. pub const ICANON: c::c_uint = linux_raw_sys::general::ICANON; +/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic. pub const PIPE_BUF: usize = linux_raw_sys::general::PIPE_BUF as usize; diff --git a/src/imp/linux_raw/net/types.rs b/src/imp/linux_raw/net/types.rs index 0a1f5b685..d0e6f6256 100644 --- a/src/imp/linux_raw/net/types.rs +++ b/src/imp/linux_raw/net/types.rs @@ -5,7 +5,7 @@ use bitflags::bitflags; #[doc(hidden)] pub type RawSocketType = u32; -/// `SOCK_*` constants for [`socket`]. +/// `SOCK_*` constants for use with [`socket`]. /// /// [`socket`]: crate::net::socket #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] @@ -226,22 +226,22 @@ impl Protocol { } } -/// `SHUT_*` constants for [`shutdown`]. +/// `SHUT_*` constants for use with [`shutdown`]. /// /// [`shutdown`]: crate::net::shutdown #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[repr(u32)] pub enum Shutdown { - /// `SHUT_RD` + /// `SHUT_WR`—Disable further read operations. Read = linux_raw_sys::general::SHUT_RD, - /// `SHUT_WR` + /// `SHUT_WR`—Disable further write operations. Write = linux_raw_sys::general::SHUT_WR, - /// `SHUT_RDWR` + /// `SHUT_RDWR`—Disable further read and write operations. ReadWrite = linux_raw_sys::general::SHUT_RDWR, } bitflags! { - /// `SOCK_*` constants for [`accept_with`] and [`acceptfrom_with`]. + /// `SOCK_*` constants for use with [`accept_with`] and [`acceptfrom_with`]. /// /// [`accept_with`]: crate::net::accept_with /// [`acceptfrom_with`]: crate::net::acceptfrom_with @@ -254,7 +254,7 @@ bitflags! { } bitflags! { - /// `SOCK_*` constants for [`socket`]. + /// `SOCK_*` constants for use with [`socket`]. /// /// [`socket`]: crate::net::socket pub struct SocketFlags: c::c_uint { diff --git a/src/imp/linux_raw/process/mod.rs b/src/imp/linux_raw/process/mod.rs index 0b07f6a52..d600312cf 100644 --- a/src/imp/linux_raw/process/mod.rs +++ b/src/imp/linux_raw/process/mod.rs @@ -8,9 +8,9 @@ pub(crate) mod cpu_set; pub(crate) use auxv::init; pub(crate) use auxv::{exe_phdrs, linux_execfn, linux_hwcap, page_size}; pub(super) use auxv::{exe_phdrs_slice, sysinfo_ehdr}; -pub(crate) use types::{raw_cpu_set_new, RawCpuSet, CPU_SETSIZE}; +pub(crate) use types::{raw_cpu_set_new, RawCpuSet, RawUname, CPU_SETSIZE}; pub use types::{ - MembarrierCommand, RawCpuid, RawGid, RawPid, RawUid, RawUname, Resource, EXIT_FAILURE, + MembarrierCommand, RawCpuid, RawGid, RawPid, RawUid, Resource, EXIT_FAILURE, EXIT_SIGNALED_SIGABRT, EXIT_SUCCESS, }; pub(crate) use wait::{ diff --git a/src/imp/linux_raw/process/types.rs b/src/imp/linux_raw/process/types.rs index effeebddf..58470af9a 100644 --- a/src/imp/linux_raw/process/types.rs +++ b/src/imp/linux_raw/process/types.rs @@ -74,16 +74,23 @@ pub enum Resource { Rttime = linux_raw_sys::general::RLIMIT_RTTIME, } +/// `EXIT_SUCCESS` pub const EXIT_SUCCESS: c::c_int = 0; +/// `EXIT_FAILURE` pub const EXIT_FAILURE: c::c_int = 1; +/// The status value of a child terminated with `SIGABRT`. pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + linux_raw_sys::general::SIGABRT as i32; +/// A process identifier as a raw integer. pub type RawPid = u32; +/// A group identifier as a raw integer. pub type RawGid = u32; +/// A user identifier as a raw integer. pub type RawUid = u32; +/// A CPU identifier as a raw integer. pub type RawCpuid = u32; -pub type RawUname = linux_raw_sys::general::new_utsname; +pub(crate) type RawUname = linux_raw_sys::general::new_utsname; #[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] diff --git a/src/imp/linux_raw/rand/types.rs b/src/imp/linux_raw/rand/types.rs index 4937de6c4..d4418d0bb 100644 --- a/src/imp/linux_raw/rand/types.rs +++ b/src/imp/linux_raw/rand/types.rs @@ -1,10 +1,13 @@ use bitflags::bitflags; bitflags! { + /// `GRND_*` flags for use with [`getrandom`]. + /// + /// [`getrandom`]: crate::rand::getrandom pub struct GetRandomFlags: u32 { - /// GRND_RANDOM + /// `GRND_RANDOM` const RANDOM = linux_raw_sys::v5_4::general::GRND_RANDOM; - /// GRND_NONBLOCK + /// `GRND_NONBLOCK` const NONBLOCK = linux_raw_sys::v5_4::general::GRND_NONBLOCK; } } diff --git a/src/imp/linux_raw/syscalls.rs b/src/imp/linux_raw/syscalls.rs index fe6d766fe..b215c3b59 100644 --- a/src/imp/linux_raw/syscalls.rs +++ b/src/imp/linux_raw/syscalls.rs @@ -497,8 +497,8 @@ pub(crate) fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result io::Result<()> { unsafe { // The raw linux syscall returns the size (in bytes) of the cpumask_t - // data type, that is used internally by the kernel to represent the - // CPU set bit mask. + // data type that is used internally by the kernel to represent the CPU + // set bit mask. let size = ret_usize(syscall3( nr(__NR_sched_getaffinity), c_uint(pid.as_raw()), @@ -507,7 +507,7 @@ pub(crate) fn sched_getaffinity(pid: Pid, cpuset: &mut RawCpuSet) -> io::Result< ))?; let bytes = (cpuset as *mut RawCpuSet).cast::(); let rest = bytes.wrapping_add(size); - // zero every byte in the cpuset, not set by the kernel + // Zero every byte in the cpuset not set by the kernel. rest.write_bytes(0, core::mem::size_of::() - size); Ok(()) } diff --git a/src/imp/linux_raw/time/types.rs b/src/imp/linux_raw/time/types.rs index 55037aaea..9f9dffa55 100644 --- a/src/imp/linux_raw/time/types.rs +++ b/src/imp/linux_raw/time/types.rs @@ -3,7 +3,10 @@ use super::super::fd::BorrowedFd; /// `struct timespec` pub type Timespec = linux_raw_sys::general::__kernel_timespec; +/// A type for the `tv_sec` field of [`Timespec`]. pub type Secs = linux_raw_sys::general::__kernel_time64_t; + +/// A type for the `tv_nsec` field of [`Timespec`]. pub type Nsecs = i64; /// `CLOCK_*` constants for use with [`clock_gettime`]. diff --git a/src/imp/mod.rs b/src/imp/mod.rs index 91f946d8b..64dacd75e 100644 --- a/src/imp/mod.rs +++ b/src/imp/mod.rs @@ -1,7 +1,5 @@ //! The "imp"-lementation module. This selects the backend to use. -#![allow(missing_docs)] - #[cfg(libc)] mod libc; #[cfg(linux_raw)] diff --git a/src/io/dup.rs b/src/io/dup.rs index f8b244f88..fd370011c 100644 --- a/src/io/dup.rs +++ b/src/io/dup.rs @@ -58,7 +58,7 @@ pub fn dup2(fd: &Fd, new: &OwnedFd) -> io::Result<()> { /// same underlying [file description] as the existing `OwnedFd` instance, /// closing `new` and reusing its file descriptor, with flags. /// -/// `dup2_with` is the same as `dup2` but adds an additional flags operand. +/// `dup2_with` is the same as [`dup2`] but adds an additional flags operand. /// /// # References /// - [POSIX] diff --git a/src/io/mmap.rs b/src/io/mmap.rs index 372d612fa..76e42bc28 100644 --- a/src/io/mmap.rs +++ b/src/io/mmap.rs @@ -184,7 +184,7 @@ pub unsafe fn mlock(ptr: *mut c_void, len: usize) -> io::Result<()> { /// `mlock2(ptr, len, flags)`—Lock memory into RAM, with /// flags. /// -/// `mlock_with` is the same as `mlock` but adds an additional flags operand. +/// `mlock_with` is the same as [`mlock`] but adds an additional flags operand. /// /// # Safety /// diff --git a/src/io/owned_fd.rs b/src/io/owned_fd.rs index 5ae201ac2..e95773df5 100644 --- a/src/io/owned_fd.rs +++ b/src/io/owned_fd.rs @@ -16,7 +16,9 @@ use core::fmt; use core::mem::{forget, ManuallyDrop}; /// A wrapper around `io_lifetimes::OwnedFd` which closes the file descriptor -/// using `rustix`'s own `close` rather than libc's `close`. +/// using `rustix`'s own [`close`] rather than libc's `close`. +/// +/// [`close`]: crate::io::close #[repr(transparent)] pub struct OwnedFd { inner: ManuallyDrop, diff --git a/src/lib.rs b/src/lib.rs index 08072b778..4fcefaf19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,47 @@ //! POSIX-like, Unix-like, Linux, and Winsock syscall-like APIs, with //! configurable backends. //! -//! The wrappers perform the following tasks: +//! For example, instead of calling libc directly, using an `unsafe` block, +//! passing a raw file descriptor, passing a raw pointer, passing a buffer +//! length, manually checking the return value for errors, and manually +//! converting the return value to the intended type: +//! +//! ```rust +//! # fn read(sock: std::net::TcpStream, buf: &mut [u8]) -> std::io::Result<()> { +//! # use std::convert::TryInto; +//! # use rustix::fd::AsRawFd; +//! # #[cfg(windows)] +//! # use winapi::um::winsock2 as libc; +//! # const MSG_PEEK: i32 = libc::MSG_PEEK; +//! let nread: usize = unsafe { +//! match libc::recv( +//! sock.as_raw_fd() as _, +//! buf.as_mut_ptr().cast(), +//! buf.len().try_into().unwrap_or(i32::MAX as _), +//! MSG_PEEK, +//! ) { +//! -1 => return Err(std::io::Error::last_os_error()), +//! nread => nread as usize, +//! } +//! }; +//! # let _ = nread; +//! # Ok(()) +//! # } +//! ``` +//! +//! With rustix you can call a safe function, pass it any type that implements +//! [`AsFd`], pass it a slice, and get a `Result` carrying the intended type: +//! +//! ```rust +//! # fn read(sock: std::net::TcpStream, buf: &mut [u8]) -> std::io::Result<()> { +//! # use rustix::net::RecvFlags; +//! let nread: usize = rustix::net::recv(&sock, buf, RecvFlags::PEEK)?; +//! # let _ = nread; +//! # Ok(()) +//! # } +//! ``` +//! +//! rustix's APIs perform the following tasks: //! - Error values are translated to [`Result`]s. //! - Buffers are passed as Rust slices. //! - Out-parameters are presented as return values. @@ -36,7 +76,7 @@ //! [`std`]: https://doc.rust-lang.org/std/ //! [`getrandom`]: https://crates.io/crates/getrandom //! [`bitflags`]: https://crates.io/crates/bitflags -//! [`AsFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.AsFd.html +//! [`AsFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsFd.html //! [`OwnedFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/struct.OwnedFd.html //! [io-lifetimes crate]: https://crates.io/crates/io-lifetimes //! [I/O-safe]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md @@ -67,10 +107,14 @@ #[cfg(not(feature = "rustc-dep-of-std"))] extern crate alloc; -/// Export `*Fd*` types and traits that we use in our public API, so that -/// our users don't need to do anything special to use the same version. +/// Export `*Fd*` types and traits that used in rustix's public API. +/// +/// Users can use this to avoid needing to import anything else to use the same +/// versions of these types and traits. /// /// Note that `OwnedFd` lives at [`rustix::io::OwnedFd`]. +/// +/// [`rustix::io::OwnedFd`]: crate::io::OwnedFd pub mod fd { use super::imp; pub use imp::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; diff --git a/src/net/send_recv.rs b/src/net/send_recv.rs index 70fd797b5..d1f2aeaf9 100644 --- a/src/net/send_recv.rs +++ b/src/net/send_recv.rs @@ -15,9 +15,11 @@ pub use imp::net::{RecvFlags, SendFlags}; /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html /// [Linux]: https://man7.org/linux/man-pages/man2/recv.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-recv #[inline] pub fn recv(fd: &Fd, buf: &mut [u8], flags: RecvFlags) -> io::Result { let fd = fd.as_fd(); @@ -29,9 +31,11 @@ pub fn recv(fd: &Fd, buf: &mut [u8], flags: RecvFlags) -> io::Result(fd: &Fd, buf: &[u8], flags: SendFlags) -> io::Result { let fd = fd.as_fd(); @@ -44,9 +48,11 @@ pub fn send(fd: &Fd, buf: &[u8], flags: SendFlags) -> io::Result( fd: &Fd, @@ -63,9 +69,11 @@ pub fn recvfrom( /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html /// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto #[inline] #[doc(alias = "sendto")] pub fn sendto_v4( @@ -84,9 +92,11 @@ pub fn sendto_v4( /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html /// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto #[inline] #[doc(alias = "sendto")] pub fn sendto_v6( @@ -105,9 +115,11 @@ pub fn sendto_v6( /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html /// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto #[inline] #[doc(alias = "sendto")] #[cfg(not(windows))] diff --git a/src/net/socket.rs b/src/net/socket.rs index f02f82695..f27125193 100644 --- a/src/net/socket.rs +++ b/src/net/socket.rs @@ -25,9 +25,11 @@ impl Default for Protocol { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html /// [Linux]: https://man7.org/linux/man-pages/man2/socket.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket #[inline] pub fn socket(domain: AddressFamily, type_: SocketType, protocol: Protocol) -> io::Result { imp::syscalls::socket(domain, type_, protocol) @@ -40,14 +42,17 @@ pub fn socket(domain: AddressFamily, type_: SocketType, protocol: Protocol) -> i /// however it is not safe in general to rely on this, as file descriptors /// may be unexpectedly allocated on other threads or in libraries. /// -/// `socket_with` is the same as `socket` but adds an additional flags operand. +/// `socket_with` is the same as [`socket`] but adds an additional flags +/// operand. /// /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html /// [Linux]: https://man7.org/linux/man-pages/man2/socket.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket #[inline] pub fn socket_with( domain: AddressFamily, @@ -64,9 +69,11 @@ pub fn socket_with( /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html /// [Linux]: https://man7.org/linux/man-pages/man2/bind.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind #[inline] #[doc(alias = "bind")] pub fn bind_v4(sockfd: &Fd, addr: &SocketAddrV4) -> io::Result<()> { @@ -80,9 +87,11 @@ pub fn bind_v4(sockfd: &Fd, addr: &SocketAddrV4) -> io::Result<()> { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html /// [Linux]: https://man7.org/linux/man-pages/man2/bind.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind #[inline] #[doc(alias = "bind")] pub fn bind_v6(sockfd: &Fd, addr: &SocketAddrV6) -> io::Result<()> { @@ -96,9 +105,11 @@ pub fn bind_v6(sockfd: &Fd, addr: &SocketAddrV6) -> io::Result<()> { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html /// [Linux]: https://man7.org/linux/man-pages/man2/bind.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind #[inline] #[doc(alias = "bind")] #[cfg(not(windows))] @@ -113,9 +124,11 @@ pub fn bind_unix(sockfd: &Fd, addr: &SocketAddrUnix) -> io::Result<()> /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html /// [Linux]: https://man7.org/linux/man-pages/man2/connect.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect #[inline] #[doc(alias = "connect")] pub fn connect_v4(sockfd: &Fd, addr: &SocketAddrV4) -> io::Result<()> { @@ -129,9 +142,11 @@ pub fn connect_v4(sockfd: &Fd, addr: &SocketAddrV4) -> io::Result<()> /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html /// [Linux]: https://man7.org/linux/man-pages/man2/connect.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect #[inline] #[doc(alias = "connect")] pub fn connect_v6(sockfd: &Fd, addr: &SocketAddrV6) -> io::Result<()> { @@ -161,9 +176,11 @@ pub fn connect_unix(sockfd: &Fd, addr: &SocketAddrUnix) -> io::Result< /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html /// [Linux]: https://man7.org/linux/man-pages/man2/listen.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen #[inline] pub fn listen(sockfd: &Fd, backlog: i32) -> io::Result<()> { let sockfd = sockfd.as_fd(); @@ -181,9 +198,11 @@ pub fn listen(sockfd: &Fd, backlog: i32) -> io::Result<()> { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html /// [Linux]: https://man7.org/linux/man-pages/man2/accept.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept #[inline] #[doc(alias = "accept4")] pub fn accept(sockfd: &Fd) -> io::Result { @@ -200,14 +219,17 @@ pub fn accept(sockfd: &Fd) -> io::Result { /// descriptor, it is not safe in general to rely on this, as file descriptors /// may be unexpectedly allocated on other threads or in libraries. /// -/// `accept_with` is the same as `accept` but adds an additional flags operand. +/// `accept_with` is the same as [`accept`] but adds an additional flags +/// operand. /// /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html /// [Linux]: https://man7.org/linux/man-pages/man2/accept4.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept #[inline] #[doc(alias = "accept4")] pub fn accept_with(sockfd: &Fd, flags: AcceptFlags) -> io::Result { @@ -223,9 +245,11 @@ pub fn accept_with(sockfd: &Fd, flags: AcceptFlags) -> io::Result(sockfd: &Fd) -> io::Result<(OwnedFd, SocketAddrAny)> { @@ -238,15 +262,17 @@ pub fn acceptfrom(sockfd: &Fd) -> io::Result<(OwnedFd, SocketAddrAny)> /// /// Use [`accept_with`] if the peer address isn't needed. /// -/// `acceptfrom_with` is the same as `acceptfrom` but adds an additional flags -/// operand. +/// `acceptfrom_with` is the same as [`acceptfrom`] but adds an additional +/// flags operand. /// /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html /// [Linux]: https://man7.org/linux/man-pages/man2/accept4.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept #[inline] #[doc(alias = "accept4")] pub fn acceptfrom_with( @@ -262,9 +288,11 @@ pub fn acceptfrom_with( /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html /// [Linux]: https://man7.org/linux/man-pages/man2/shutdown.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-shutdown #[inline] pub fn shutdown(sockfd: &Fd, how: Shutdown) -> io::Result<()> { let sockfd = sockfd.as_fd(); @@ -276,9 +304,11 @@ pub fn shutdown(sockfd: &Fd, how: Shutdown) -> io::Result<()> { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html /// [Linux]: https://man7.org/linux/man-pages/man2/getsockname.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockname #[inline] pub fn getsockname(sockfd: &Fd) -> io::Result { let sockfd = sockfd.as_fd(); @@ -291,9 +321,11 @@ pub fn getsockname(sockfd: &Fd) -> io::Result { /// # References /// - [POSIX] /// - [Linux] +/// - [Winsock] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html /// [Linux]: https://man7.org/linux/man-pages/man2/getpeername.2.html +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getpeername #[inline] pub fn getpeername(sockfd: &Fd) -> io::Result { let sockfd = sockfd.as_fd(); diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index cfe4f7380..5a21dc258 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -19,11 +19,15 @@ pub use imp::net::Timeout; /// - [POSIX `sys/socket.h`] /// - [Linux `getsockopt`] /// - [Linux `socket`] +/// - [Winsock `getsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_TYPE")] pub fn get_socket_type(fd: &Fd) -> io::Result { @@ -38,11 +42,15 @@ pub fn get_socket_type(fd: &Fd) -> io::Result { /// - [POSIX `sys/socket.h`] /// - [Linux `setsockopt`] /// - [Linux `socket`] +/// - [Winsock `setsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_REUSEADDR")] pub fn set_socket_reuseaddr(fd: &Fd, value: bool) -> io::Result<()> { @@ -57,11 +65,15 @@ pub fn set_socket_reuseaddr(fd: &Fd, value: bool) -> io::Result<()> { /// - [POSIX `sys/socket.h`] /// - [Linux `setsockopt`] /// - [Linux `socket`] +/// - [Winsock `setsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_BROADCAST")] pub fn set_socket_broadcast(fd: &Fd, broadcast: bool) -> io::Result<()> { @@ -76,11 +88,15 @@ pub fn set_socket_broadcast(fd: &Fd, broadcast: bool) -> io::Result<() /// - [POSIX `sys/socket.h`] /// - [Linux `getsockopt`] /// - [Linux `socket`] +/// - [Winsock `getsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_BROADCAST")] pub fn get_socket_broadcast(fd: &Fd) -> io::Result { @@ -95,11 +111,15 @@ pub fn get_socket_broadcast(fd: &Fd) -> io::Result { /// - [POSIX `sys/socket.h`] /// - [Linux `setsockopt`] /// - [Linux `socket`] +/// - [Winsock `setsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_LINGER")] pub fn set_socket_linger(fd: &Fd, linger: Option) -> io::Result<()> { @@ -112,13 +132,17 @@ pub fn set_socket_linger(fd: &Fd, linger: Option) -> io::Res /// # References /// - [POSIX `getsockopt`] /// - [POSIX `sys/socket.h`] -/// - [Linux `getsockopt] +/// - [Linux `getsockopt`] /// - [Linux `socket`] +/// - [Winsock `getsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html -/// [Linux `getsockopt]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_LINGER")] pub fn get_socket_linger(fd: &Fd) -> io::Result> { @@ -166,11 +190,15 @@ pub fn get_socket_passcred(fd: &Fd) -> io::Result { /// - [POSIX `sys/socket.h`] /// - [Linux `setsockopt`] /// - [Linux `socket`] +/// - [Winsock `setsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_RCVTIMEO")] #[doc(alias = "SO_SNDTIMEO")] @@ -190,11 +218,15 @@ pub fn set_socket_timeout( /// - [POSIX `sys/socket.h`] /// - [Linux `getsockopt`] /// - [Linux `socket`] +/// - [Winsock `getsockopt`] +/// - [Winsock `SOL_SOCKET` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options #[inline] #[doc(alias = "SO_RCVTIMEO")] #[doc(alias = "SO_SNDTIMEO")] @@ -210,10 +242,14 @@ pub fn get_socket_timeout(fd: &Fd, id: Timeout) -> io::Result(fd: &Fd, ttl: u32) -> io::Result<()> { @@ -228,11 +264,15 @@ pub fn set_ip_ttl(fd: &Fd, ttl: u32) -> io::Result<()> { /// - [POSIX `netinet/in.h`] /// - [Linux `getsockopt`] /// - [Linux `ip`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_TTL")] pub fn get_ip_ttl(fd: &Fd) -> io::Result { @@ -247,11 +287,15 @@ pub fn get_ip_ttl(fd: &Fd) -> io::Result { /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ipv6`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_V6ONLY")] pub fn set_ipv6_v6only(fd: &Fd, only_v6: bool) -> io::Result<()> { @@ -266,11 +310,15 @@ pub fn set_ipv6_v6only(fd: &Fd, only_v6: bool) -> io::Result<()> { /// - [POSIX `netinet/in.h`] /// - [Linux `getsockopt`] /// - [Linux `ipv6`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_V6ONLY")] pub fn get_ipv6_v6only(fd: &Fd) -> io::Result { @@ -285,11 +333,15 @@ pub fn get_ipv6_v6only(fd: &Fd) -> io::Result { /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ip`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_MULTICAST_LOOP")] pub fn set_ip_multicast_loop(fd: &Fd, multicast_loop: bool) -> io::Result<()> { @@ -304,11 +356,15 @@ pub fn set_ip_multicast_loop(fd: &Fd, multicast_loop: bool) -> io::Res /// - [POSIX `netinet/in.h`] /// - [Linux `getsockopt`] /// - [Linux `ip`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_MULTICAST_LOOP")] pub fn get_ip_multicast_loop(fd: &Fd) -> io::Result { @@ -323,11 +379,15 @@ pub fn get_ip_multicast_loop(fd: &Fd) -> io::Result { /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ip`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_MULTICAST_TTL")] pub fn set_ip_multicast_ttl(fd: &Fd, multicast_ttl: u32) -> io::Result<()> { @@ -342,11 +402,15 @@ pub fn set_ip_multicast_ttl(fd: &Fd, multicast_ttl: u32) -> io::Result /// - [POSIX `netinet/in.h`] /// - [Linux `getsockopt`] /// - [Linux `ip`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_MULTICAST_TTL")] pub fn get_ip_multicast_ttl(fd: &Fd) -> io::Result { @@ -361,11 +425,15 @@ pub fn get_ip_multicast_ttl(fd: &Fd) -> io::Result { /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ipv6`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_MULTICAST_LOOP")] pub fn set_ipv6_multicast_loop(fd: &Fd, multicast_loop: bool) -> io::Result<()> { @@ -380,11 +448,15 @@ pub fn set_ipv6_multicast_loop(fd: &Fd, multicast_loop: bool) -> io::R /// - [POSIX `netinet/in.h`] /// - [Linux `getsockopt`] /// - [Linux `ipv6`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_MULTICAST_LOOP")] pub fn get_ipv6_multicast_loop(fd: &Fd) -> io::Result { @@ -399,11 +471,15 @@ pub fn get_ipv6_multicast_loop(fd: &Fd) -> io::Result { /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ip`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_ADD_MEMBERSHIP")] pub fn set_ip_add_membership( @@ -422,13 +498,17 @@ pub fn set_ip_add_membership( /// # References /// - [POSIX `setsockopt`] /// - [POSIX `netinet/in.h`] -/// - [Linux `setsockopt] +/// - [Linux `setsockopt`] /// - [Linux `ipv6] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_JOIN_GROUP")] #[doc(alias = "IPV6_ADD_MEMBERSHIP")] @@ -448,11 +528,15 @@ pub fn set_ipv6_add_membership( /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ip`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IP` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ip`]: https://man7.org/linux/man-pages/man7/ip.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options #[inline] #[doc(alias = "IP_DROP_MEMBERSHIP")] pub fn set_ip_drop_membership( @@ -473,11 +557,15 @@ pub fn set_ip_drop_membership( /// - [POSIX `netinet/in.h`] /// - [Linux `setsockopt`] /// - [Linux `ipv6`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_IPV6` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options #[inline] #[doc(alias = "IPV6_LEAVE_GROUP")] #[doc(alias = "IPV6_DROP_MEMBERSHIP")] @@ -497,11 +585,15 @@ pub fn set_ipv6_drop_membership( /// - [POSIX `netinet/tcp.h`] /// - [Linux `setsockopt`] /// - [Linux `tcp`] +/// - [Winsock `setsockopt`] +/// - [Winsock `IPPROTO_TCP` options] /// /// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html /// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html /// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html /// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options #[inline] #[doc(alias = "TCP_NODELAY")] pub fn set_tcp_nodelay(fd: &Fd, nodelay: bool) -> io::Result<()> { @@ -516,11 +608,15 @@ pub fn set_tcp_nodelay(fd: &Fd, nodelay: bool) -> io::Result<()> { /// - [POSIX `netinet/tcp.h`] /// - [Linux `getsockopt`] /// - [Linux `tcp`] +/// - [Winsock `getsockopt`] +/// - [Winsock `IPPROTO_TCP` options] /// /// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html /// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html /// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html /// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options #[inline] #[doc(alias = "TCP_NODELAY")] pub fn get_tcp_nodelay(fd: &Fd) -> io::Result { diff --git a/src/net/wsa.rs b/src/net/wsa.rs index 73b1788fd..3f7ad3238 100644 --- a/src/net/wsa.rs +++ b/src/net/wsa.rs @@ -6,6 +6,11 @@ use winapi::um::winsock2::{WSACleanup, WSAGetLastError, WSAStartup, WSADATA}; /// /// On Windows, it's necessary to initialize the sockets subsystem before /// using sockets APIs. The function performs the necessary initialization. +/// +/// # References +/// - [Winsock] +/// +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup pub fn wsa_startup() -> io::Result { // Request version 2.2, which has been the latest version since far older // versions of Windows than we support here. For more information about @@ -28,6 +33,11 @@ pub fn wsa_startup() -> io::Result { /// /// In a program where `init` is called, if sockets are no longer necessary, /// this function releases associated resources. +/// +/// # References +/// - [Winsock] +/// +/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsacleanup pub fn wsa_cleanup() -> io::Result<()> { unsafe { if WSACleanup() == 0 { diff --git a/src/runtime.rs b/src/runtime.rs index 18a166074..19619350e 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -18,9 +18,8 @@ #![allow(unsafe_code)] use crate::ffi::ZStr; -use crate::path::Arg; use crate::process::Pid; -use crate::{imp, io}; +use crate::{imp, io, path}; use alloc::borrow::Cow; use alloc::vec::Vec; use core::ffi::c_void; @@ -101,29 +100,60 @@ pub use imp::thread::tls::StartupTlsInfo; /// `fork()`—Creates a new process by duplicating the calling process. /// -/// On success, the PID of the child process is returned in the parent, -/// and `Pid::NONE` is returned in the child. +/// On success, the PID of the child process is returned in the parent, and +/// `Pid::NONE` is returned in the child. /// -/// Unlike its libc counterpart, -/// this function does not call handlers registered with [`pthread_atfork`], -/// and does not initializes the `pthread` data structures in the child -/// process. +/// If the parent has multiple threads, fork creates a child process containing +/// a copy of all the memory of all the threads, but with only one actual +/// thread. Mutexes held on threads other than the one that called `fork` in +/// the parent will appear in the child as if they are locked indefinitely, +/// and attempting to lock them may deadlock. +/// +/// Unlike its libc counterpart, this function does not call handlers +/// registered with [`pthread_atfork`]. /// /// # Safety /// -/// If the parent has multiple threads, fork creates a child process containing -/// a copy of all the memory of all the threads, but with only one actual -/// thread, so objects in memory such as mutexes may be in unusable states. +/// This function does not update the threading runtime's data structures in +/// the child process, so higher-level APIs such as `pthread_self` may return +/// stale values in the child. +/// +/// And because it doesn't call handlers registered with `pthread_atfork`, +/// random number generators such as those in the [rand] crate aren't +/// reinitialized in the child, so may generate the same values in the child +/// as in the parent. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/fork.2.html /// [`pthread_atfork`]: https://man7.org/linux/man-pages/man3/pthread_atfork.3.html +/// [rand]: https://crates.io/crates/rand pub unsafe fn fork() -> io::Result { imp::syscalls::fork() } +/// Executes the program pointed to by `path`, with the arguments `args`, and +/// the environment variables `env_vars`. +/// +/// The first argument, by convention, should be the filename associated with +/// the file being executed. +pub fn execve( + path: P, + args: &[A], + env_vars: &[E], +) -> io::Result<()> { + let arg_zstr: Vec> = args + .iter() + .map(path::Arg::as_cow_z_str) + .collect::>()?; + let env_zstr: Vec> = env_vars + .iter() + .map(path::Arg::as_cow_z_str) + .collect::>()?; + path.into_with_z_str(|path_zstr| _execve(path_zstr, &arg_zstr, &env_zstr)) +} + fn _execve(path: &ZStr, arg_zstr: &[Cow<'_, ZStr>], env_zstr: &[Cow<'_, ZStr>]) -> io::Result<()> { let arg_ptrs: Vec<_> = arg_zstr .iter() @@ -137,20 +167,3 @@ fn _execve(path: &ZStr, arg_zstr: &[Cow<'_, ZStr>], env_zstr: &[Cow<'_, ZStr>]) .collect(); unsafe { imp::syscalls::execve(path, &arg_ptrs, &env_ptrs) } } - -/// Executes the program pointed to by `path`, with the arguments `args`, -/// and the environment variables `env_vars`. -/// -/// The first argument, by convention, -/// should be the filename associated with the file being executed. -pub fn execve(path: P, args: &[A], env_vars: &[E]) -> io::Result<()> { - let arg_zstr: Vec> = args - .iter() - .map(Arg::as_cow_z_str) - .collect::>()?; - let env_zstr: Vec> = env_vars - .iter() - .map(Arg::as_cow_z_str) - .collect::>()?; - path.into_with_z_str(|path_zstr| _execve(path_zstr, &arg_zstr, &env_zstr)) -}