Skip to content

Commit

Permalink
upgrade to libuv v1.49.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatcuk committed Nov 12, 2024
1 parent df3f9e1 commit 0212ef1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libuv"
version = "2.9.0"
version = "2.10.0"
description = "A safe rust wrapper for libuv"
homepage = "https://github.com/bmatcuk/libuv-rs"
repository = "https://github.com/bmatcuk/libuv-rs"
Expand All @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
bitflags = "~1.2.1"
libuv-sys2 = "~1.48.0"
libuv-sys2 = "~1.49.2"

[dev-dependencies]
rand = "~0.7.3"
Expand Down
9 changes: 6 additions & 3 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//! Starting with libuv v1.45.0, some file operations on Linux are handed off to io_uring
//! <https://en.wikipedia.org/wiki/Io_uring> when possible. Apart from a (sometimes significant)
//! increase in throughput there should be no change in observable behavior. Libuv reverts to using
//! its threadpool when the necessary kernel features are unavailable or unsuitable.
//! its threadpool when the necessary kernel features are unavailable or unsuitable. Starting with
//! libuv v1.49.0 this behavior was reverted and Libuv on Linux by default will be using the
//! threadpool again. In order to enable io_uring the Loop instance must be configured with the
//! ENABLE_IO_URING_SQPOLL option.
//!
//! Note: Uses utf-8 encoding on Windows
Expand Down Expand Up @@ -1384,7 +1387,7 @@ impl crate::Loop {
result.map(|_| req)
}

/// Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandle. The path can be
/// Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandleW. The path can be
/// read from FsReq::real_path()
///
/// Warning: This function has certain platform-specific caveats that were discovered when used
Expand Down Expand Up @@ -1413,7 +1416,7 @@ impl crate::Loop {
self._fs_realpath(path, cb)
}

/// Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandle.
/// Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandleW.
///
/// Warning: This function has certain platform-specific caveats that were discovered when used
/// in Node.
Expand Down
2 changes: 2 additions & 0 deletions src/handles/fs_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl FsEventHandle {
/// Start the handle with the given callback, which will watch the specified path for changes.
///
/// Note: Currently the only supported flag is RECURSIVE and only on OSX and Windows.
/// Note: On macOS, events collected by the OS immediately before calling start might be
/// reported to the callback.
pub fn start<CB: Into<FsEventCB<'static>>>(
&mut self,
path: &str,
Expand Down
23 changes: 18 additions & 5 deletions src/handles/streams/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ bitflags! {
pub struct TcpBindFlags: u32 {
/// Dual-stack support is disabled and only IPv6 is used.
const IPV6ONLY = uv::uv_tcp_flags_UV_TCP_IPV6ONLY as _;

/// Enable REUSEPORT socket option when binding the handle. This allows completely
/// duplicate bindings by multiple processes or threads if they all set REUSEPORT before
/// binding the port. Incoming connections are distributed across the participating
/// listener sockets.
///
/// This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris
/// 11.4, and AIX 7.2.5+ for now.
const REUSEPORT = uv::uv_tcp_flags_UV_TCP_REUSEPORT as _;
}
}

Expand Down Expand Up @@ -127,6 +136,8 @@ impl TcpHandle {
/// After delay has been reached, 10 successive probes, each spaced 1 second from the previous
/// one, will still happen. If the connection is still lost at the end of this procedure, then
/// the handle is destroyed with a ETIMEDOUT error passed to the corresponding callback.
///
/// If `delay` is less than 1 then EINVAL is returned.
pub fn keepalive(&mut self, enable: bool, delay: u32) -> crate::Result<()> {
crate::uvret(unsafe { uv_tcp_keepalive(self.handle, if enable { 1 } else { 0 }, delay) })
}
Expand All @@ -145,12 +156,14 @@ impl TcpHandle {

/// Bind the handle to an address and port.
///
/// When the port is already taken, you can expect to see an EADDRINUSE error from listen() or
/// connect(). That is, a successful call to this function does not guarantee that the call to
/// listen() or connect() will succeed as well.
/// When the port is already taken, you can expect to see an EADDRINUSE error from listen or
/// connect unless you specify REUSEPORT in `flags` for all the binding sockets. That is, a
/// successful call to this function does not guarantee that the call to listen or connect will
/// succeed as well.
///
/// flags can contain IPV6ONLY, in which case dual-stack support is disabled and only IPv6 is
/// used.
/// Note: REUSEPORT flag is available only on Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+,
/// Solaris 11.4, and AIX 7.2.5+ at the moment. On other platforms this function will return an
/// ENOTSUP error.
pub fn bind(
&mut self,
addr: &SocketAddr,
Expand Down
23 changes: 17 additions & 6 deletions src/handles/streams/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,30 @@ bitflags! {
/// Disables dual stack mode.
const IPV6ONLY = uv::uv_udp_flags_UV_UDP_IPV6ONLY as _;

/// Indicates if SO_REUSEADDR will be set when binding the handle in bind(). This sets the
/// SO_REUSEPORT socket flag on the BSDs and OS X. On other Unix platforms, it sets the
/// SO_REUSEADDR flag. What that means is that multiple threads or processes can bind to
/// the same address without error (provided they all set the flag) but only the last one
/// to bind will receive any traffic, in effect "stealing" the port from the previous
/// listener.
/// Indicates if SO_REUSEADDR will be set when binding the handle. This sets the
/// SO_REUSEPORT socket flag on the BSDs (except for DragonFlyBSD), OS X, and other
/// platforms where SO_REUSEPORTs don't have the capability of load balancing, as the
/// opposite of what REUSEPORT would do. On other Unix platforms, it sets the SO_REUSEADDR
/// flag. What that means is that multiple threads or processes can bind to the same
/// address without error (provided they all set the flag) but only the last one to bind
/// will receive any traffic, in effect "stealing" the port from the previous listener.
const REUSEADDR = uv::uv_udp_flags_UV_UDP_REUSEADDR as _;

/// Indicates if IP_RECVERR/IPV6_RECVERR will be set when binding the handle. This sets
/// IP_RECVERR for IPv4 and IPV6_RECVERR for IPv6 UDP sockets on Linux. This stops the
/// Linux kernel from suppressing some ICMP error messages and enables full ICMP error
/// reporting for faster failover. This flag is no-op on platforms other than Linux.
const RECVERR = uv::uv_udp_flags_UV_UDP_LINUX_RECVERR as _;

/// Indicates if SO_REUSEPORT will be set when binding the handle. This sets the
/// SO_REUSEPORT socket option on supported platforms. Unlike UV_UDP_REUSEADDR, this flag
/// will make multiple threads or processes that are binding to the same address and port
/// "share" the port, which means incoming datagrams are distributed across the receiving
/// sockets among threads or processes.
///
/// This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris
/// 11.4, and AIX 7.2.5+ for now.
const REUSEPORT = uv::uv_udp_flags_UV_UDP_REUSEPORT as _;
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::{FromInner, HandleTrait, IntoInner};
use uv::{
uv_backend_fd, uv_backend_timeout, uv_default_loop, uv_handle_t, uv_loop_alive, uv_loop_close,
uv_loop_configure, uv_loop_delete, uv_loop_fork, uv_loop_get_data, uv_loop_init, uv_loop_new,
uv_loop_option_UV_LOOP_BLOCK_SIGNAL, uv_loop_option_UV_METRICS_IDLE_TIME, uv_loop_set_data,
uv_loop_t, uv_metrics_idle_time, uv_metrics_info, uv_metrics_t, uv_now, uv_run, uv_run_mode,
uv_run_mode_UV_RUN_DEFAULT, uv_run_mode_UV_RUN_NOWAIT, uv_run_mode_UV_RUN_ONCE, uv_stop,
uv_update_time, uv_walk,
uv_loop_option_UV_LOOP_BLOCK_SIGNAL, uv_loop_option_UV_LOOP_USE_IO_URING_SQPOLL,
uv_loop_option_UV_METRICS_IDLE_TIME, uv_loop_set_data, uv_loop_t, uv_metrics_idle_time,
uv_metrics_info, uv_metrics_t, uv_now, uv_run, uv_run_mode, uv_run_mode_UV_RUN_DEFAULT,
uv_run_mode_UV_RUN_NOWAIT, uv_run_mode_UV_RUN_ONCE, uv_stop, uv_update_time, uv_walk,
};

/// Mode used to run the loop.
Expand Down Expand Up @@ -171,6 +171,13 @@ impl Loop {
crate::uvret(unsafe { uv_loop_configure(self.handle, uv_loop_option_UV_METRICS_IDLE_TIME) })
}

/// Enable SQPOLL io_uring instance to handle asynchronous file system operations.
pub fn enable_io_uring_sqpoll(&mut self) -> crate::Result<()> {
crate::uvret(unsafe {
uv_loop_configure(self.handle, uv_loop_option_UV_LOOP_USE_IO_URING_SQPOLL)
})
}

/// Releases all internal loop resources. Call this function only when the loop has finished
/// executing and all open handles and requests have been closed, or it will return
/// Error::EBUSY. After this function returns, the user can free the memory allocated for the
Expand Down
63 changes: 61 additions & 2 deletions src/misc/os.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{FromInner, IntoInner};
use std::ffi::CStr;
use uv::{
uv_available_parallelism, uv_os_free_passwd, uv_os_get_passwd, uv_os_gethostname, uv_os_getpid,
uv_os_getppid, uv_os_getpriority, uv_os_setpriority, uv_os_uname, uv_passwd_t, uv_utsname_t,
uv_available_parallelism, uv_group_t, uv_os_free_group, uv_os_free_passwd, uv_os_get_group,
uv_os_get_passwd, uv_os_get_passwd2, uv_os_gethostname, uv_os_getpid, uv_os_getppid,
uv_os_getpriority, uv_os_setpriority, uv_os_uname, uv_passwd_t, uv_utsname_t,
UV_MAXHOSTNAMESIZE,
};

Expand Down Expand Up @@ -55,6 +56,40 @@ impl FromInner<uv_passwd_t> for User {
}
}

/// Data type for group file information.
pub struct Group {
pub groupname: String,
pub gid: Option<crate::Gid>,
pub members: Vec<String>,
}

impl FromInner<uv_group_t> for Group {
fn from_inner(group: uv_group_t) -> Group {
let groupname = unsafe { CStr::from_ptr(group.groupname) }
.to_string_lossy()
.into_owned();
let gid = if group.gid >= 0 {
Some(group.gid as _)
} else {
None
};
let mut members = Vec::new();
let mut members_ptr = group.members;
unsafe {
while let Some(member_ptr) = members_ptr.as_ref() {
let member = CStr::from_ptr(*member_ptr).to_string_lossy().into_owned();
members.push(member);
members_ptr = members_ptr.offset(1);
}
}
Group {
groupname,
gid,
members,
}
}
}

/// Data type for operating system name and version information.
pub struct SystemInfo {
pub sysname: String,
Expand Down Expand Up @@ -99,6 +134,30 @@ pub fn get_passwd() -> crate::Result<User> {
Ok(result)
}

/// Gets a subset of the password file entry for the provided uid. The populated data includes the
/// username, euid, gid, shell, and home directory. On non-Windows systems, all data comes from
/// getpwuid_r(3). On Windows, uid, gid, and shell are set to None and have no meaning.
pub fn get_passwd2(uid: crate::Uid) -> crate::Result<User> {
let mut passwd: uv_passwd_t = unsafe { std::mem::zeroed() };
crate::uvret(unsafe { uv_os_get_passwd2(&mut passwd as _, uid) })?;

let result = passwd.into_inner();
unsafe { uv_os_free_passwd(&mut passwd as _) };
Ok(result)
}

/// Gets a subset of the group file entry for the provided uid. The populated data includes the
/// group name, gid, and members. On non-Windows systems, all data comes from getgrgid_r(3). On
/// Windows, uid and gid are set to None and have no meaning.
pub fn get_group(gid: crate::Gid) -> crate::Result<Group> {
let mut group: uv_group_t = unsafe { std::mem::zeroed() };
crate::uvret(unsafe { uv_os_get_group(&mut group as _, gid) })?;

let result = group.into_inner();
unsafe { uv_os_free_group(&mut group as _) };
Ok(result)
}

/// Returns the hostname
pub fn gethostname() -> crate::Result<String> {
let mut size = UV_MAXHOSTNAMESIZE as usize;
Expand Down

0 comments on commit 0212ef1

Please sign in to comment.