Struct libuv::loop::Loop

source ·
pub struct Loop { /* private fields */ }
Expand description

The event loop is the central part of libuv’s functionality. It takes care of polling for i/o and scheduling callbacks to be run based on different sources of events.

Implementations§

source§

impl Loop

source

pub fn new() -> Result<Loop>

Creates a new Loop.

source

pub fn default() -> Result<Loop>

Returns the initialized default loop.

This function is just a convenient way for having a global loop throughout an application, the default loop is in no way different than the ones initialized with new(). As such, the default loop can (and should) be closed with close() so the resources associated with it are freed.

Warning: This function is not thread safe.

source

pub fn block_signal(&mut self, signum: i32) -> Result<()>

Block a signal when polling for new events. The second argument to configure() is the signal number.

This operation is currently only implemented for SIGPROF signals, to suppress unnecessary wakeups when using a sampling profiler. Requesting other signals will fail with UV_EINVAL.

source

pub fn accumulate_idle_time(&mut self) -> Result<()>

Accumulate the amount of idle time the event loop spends in the event provider.

This option is necessary to use metrics_idle_time().

source

pub fn close(&mut self) -> Result<()>

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 loop.

source

pub fn run(&mut self, mode: RunMode) -> Result<i32>

This function runs the event loop. It will act differently depending on the specified mode. run() is not reentrant. It must not be called from a callback.

source

pub fn is_alive(&self) -> bool

Returns true if there are referenced active handles, active requests or closing handles in the loop.

source

pub fn idle_time(&self) -> u64

Retrieve the amount of time the event loop has been idle in the kernel’s event provider (e.g. epoll_wait). The call is thread safe.

The return value is the accumulated time spent idle in the kernel’s event provider starting from when the loop was configured to collect the idle time.

Note The event loop will not begin accumulating the event provider’s idle time until calling accumulate_idle_time().

source

pub fn metrics_info(&self) -> Result<Metrics>

The current set of event loop metrics.

source

pub fn stop(&mut self)

Stop the event loop, causing run() to end as soon as possible. This will happen not sooner than the next loop iteration. If this function was called before blocking for i/o, the loop won’t block for i/o on this iteration.

source

pub fn backend_fd(&self) -> i32

Get backend file descriptor. Only kqueue, epoll and event ports are supported.

This can be used in conjunction with run(NoWait) to poll in one thread and run the event loop’s callbacks in another see test/test-embed.c for an example.

Note: Embedding a kqueue fd in another kqueue pollset doesn’t work on all platforms. It’s not an error to add the fd but it never generates events.

source

pub fn backend_timeout(&self) -> i32

Get the poll timeout. The return value is in milliseconds, or -1 for no timeout.

source

pub fn now(&self) -> u64

Return the current timestamp in milliseconds. The timestamp is cached at the start of the event loop tick, see update_time() for details and rationale.

The timestamp increases monotonically from some arbitrary point in time. Don’t make assumptions about the starting point, you will only get disappointed.

source

pub fn update_time(&mut self)

Update the event loop’s concept of “now”. Libuv caches the current time at the start of the event loop tick in order to reduce the number of time-related system calls.

You won’t normally need to call this function unless you have callbacks that block the event loop for longer periods of time, where “longer” is somewhat subjective but probably on the order of a millisecond or more.

source

pub fn walk(&self, cb: impl FnMut(Handle) + 'static)

Walk the list of handles.

source

pub fn fork(&mut self) -> Result<()>

Reinitialize any kernel state necessary in the child process after a fork(2) system call.

Previously started watchers will continue to be started in the child process.

It is necessary to explicitly call this function on every event loop created in the parent process that you plan to continue to use in the child, including the default loop (even if you don’t continue to use it in the parent). This function must be called before calling run() or any other API function using the loop in the child. Failure to do so will result in undefined behaviour, possibly including duplicate events delivered to both parent and child or aborting the child process.

When possible, it is preferred to create a new loop in the child process instead of reusing a loop created in the parent. New loops created in the child process after the fork should not use this function.

This function is not implemented on Windows, where it returns UV_ENOSYS.

Caution: This function is experimental. It may contain bugs, and is subject to change or removal. API and ABI stability is not guaranteed.

Note: On Mac OS X, if directory FS event handles were in use in the parent process for any event loop, the child process will no longer be able to use the most efficient FSEvent implementation. Instead, uses of directory FS event handles in the child will fall back to the same implementation used for files and on other kqueue-based systems.

Caution: On AIX and SunOS, FS event handles that were already started in the parent process at the time of forking will not deliver events in the child process; they must be closed and restarted. On all other platforms, they will continue to work normally without any further intervention.

source§

impl Loop

source

pub fn fs_close<CB: Into<FsCB<'static>>>( &self, file: File, cb: CB ) -> Result<FsReq>

Equivalent to close(2).

source

pub fn fs_close_sync(&self, file: File) -> Result<usize>

Equivalent to close(2).

source

pub fn fs_open<CB: Into<FsCB<'static>>>( &self, path: &str, flags: FsOpenFlags, mode: FsModeFlags, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to open(2).

Note: On Windows libuv uses CreateFileW and thus the file is always opened in binary mode.

source

pub fn fs_open_sync( &self, path: &str, flags: FsOpenFlags, mode: FsModeFlags ) -> Result<File, Box<dyn Error>>

Equivalent to open(2).

Note: On Windows libuv uses CreateFileW and thus the file is always opened in binary mode.

source

pub fn fs_read<CB: Into<FsCB<'static>>>( &self, file: File, bufs: &[Buf], offset: i64, cb: CB ) -> Result<FsReq>

Equivalent to preadv(2).

Warning: On Windows, under non-MSVC environments (e.g. when GCC or Clang is used to build libuv), files opened using the Filemap flag may cause a fatal crash if the memory mapped read operation fails.

source

pub fn fs_read_sync( &self, file: File, bufs: &[Buf], offset: i64 ) -> Result<usize>

Equivalent to preadv(2).

Warning: On Windows, under non-MSVC environments (e.g. when GCC or Clang is used to build libuv), files opened using the Filemap flag may cause a fatal crash if the memory mapped read operation fails.

Equivalent to unlink(2).

Equivalent to unlink(2).

source

pub fn fs_write<CB: Into<FsCB<'static>>>( &self, file: File, bufs: &[impl BufTrait], offset: i64, cb: CB ) -> Result<FsReq>

Equivalent to pwritev(2).

Warning: On Windows, under non-MSVC environments (e.g. when GCC or Clang is used to build libuv), files opened using the Filemap flag may cause a fatal crash if the memory mapped write operation fails.

source

pub fn fs_write_sync( &self, file: File, bufs: &[impl BufTrait], offset: i64 ) -> Result<usize>

Equivalent to pwritev(2).

Warning: On Windows, under non-MSVC environments (e.g. when GCC or Clang is used to build libuv), files opened using the Filemap flag may cause a fatal crash if the memory mapped write operation fails.

source

pub fn fs_mkdir<CB: Into<FsCB<'static>>>( &self, path: &str, mode: FsModeFlags, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to mkdir(2).

Note: mode is currently not implemented on Windows.

source

pub fn fs_mkdir_sync( &self, path: &str, mode: FsModeFlags ) -> Result<usize, Box<dyn Error>>

Equivalent to mkdir(2).

Note: mode is currently not implemented on Windows.

source

pub fn fs_mkdtemp<CB: Into<FsCB<'static>>>( &self, tpl: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to mkdtemp(3). The result can be found as req.path()

source

pub fn fs_mkdtemp_sync(&self, tpl: &str) -> Result<String, Box<dyn Error>>

Equivalent to mkdtemp(3).

source

pub fn fs_mkstemp<CB: Into<FsCB<'static>>>( &self, tpl: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to mkstemp(3).

source

pub fn fs_mkstemp_sync(&self, tpl: &str) -> Result<usize, Box<dyn Error>>

Equivalent to mkstemp(3).

source

pub fn fs_rmdir<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to rmdir(2).

source

pub fn fs_rmdir_sync(&self, path: &str) -> Result<usize, Box<dyn Error>>

Equivalent to rmdir(2).

source

pub fn fs_opendir<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Opens path as a directory stream. On success, a Dir is allocated and returned via req.dir(). This memory is not freed by req.destroy(). The allocated memory must be freed by calling fs_closedir(). On failure, no memory is allocated.

The contents of the directory can be iterated over by passing the resulting Dir to fs_readdir().

source

pub fn fs_opendir_sync(&self, path: &str) -> Result<Dir, Box<dyn Error>>

Opens path as a directory stream. On success, a Dir is allocated and returned. The allocated memory must be freed by calling fs_closedir(). On failure, no memory is allocated.

The contents of the directory can be iterated over by passing the resulting Dir to fs_readdir().

source

pub fn fs_closedir<CB: Into<FsCB<'static>>>( &self, dir: &Dir, cb: CB ) -> Result<FsReq>

Closes the directory stream represented by dir and frees the memory allocated by fs_opendir(). Don’t forget to call Dir::free_entries() first!

source

pub fn fs_closedir_sync(&self, dir: &Dir) -> Result<usize>

Closes the directory stream represented by dir and frees the memory allocated by fs_opendir(). Don’t forget to call Dir::free_entries() first!

source

pub fn fs_readdir<CB: Into<FsCB<'static>>>( &self, dir: &Dir, cb: CB ) -> Result<FsReq>

Iterates over the directory stream, dir, returned by a successful fs_opendir() call. Prior to invoking fs_readdir(), the caller must allocate space for directory entries by calling Dir::reserve().

Warning: fs_readdir() is not thread safe.

Note: This function does not return the “.” and “..” entries.

Note: On success this function allocates memory that must be freed using FsReq::destroy(). destroy() must be called before closing the directory with fs_closedir().

source

pub fn fs_readdir_sync(&self, dir: &Dir) -> Result<usize>

Iterates over the directory stream, dir, returned by a successful fs_opendir() call. Prior to invoking fs_readdir(), the caller must allocate space for directory entries by calling Dir::reserve().

On success, the result is an integer >= 0 representing the number of entries read from the stream.

Warning: fs_readdir() is not thread safe.

Note: This function does not return the “.” and “..” entries.

source

pub fn fs_scandir( &self, path: &str, flags: FsOpenFlags, cb: impl FnMut(ScandirIter) + 'static ) -> Result<FsReq, Box<dyn Error>>

Start scanning a directory. Unlike most other fs_* methods, the callback is passed a ScandirIter which is an iterator over the entries in the directory. If you need access to the FsReq in the callback, you can access iter.req.

Note: Unlike scandir(3), this function does not return the “.” and “..” entries.

Note: On Linux, getting the type of an entry is only supported by some file systems (btrfs, ext2, ext3 and ext4 at the time of this writing), check the getdents(2) man page.

source

pub fn fs_scandir_sync( &self, path: &str, flags: FsOpenFlags ) -> Result<ScandirIter, Box<dyn Error>>

Returns a ScandirIter that can be used to iterate over the contents of a directory.

source

pub fn fs_stat<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to stat(2).

source

pub fn fs_stat_sync(&self, path: &str) -> Result<Stat, Box<dyn Error>>

Equivalent to stat(2).

source

pub fn fs_fstat<CB: Into<FsCB<'static>>>( &self, file: File, cb: CB ) -> Result<FsReq>

Equivalent to fstat(2).

source

pub fn fs_fstat_sync(&self, file: File) -> Result<Stat>

Equivalent to fstat(2).

source

pub fn fs_lstat<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to lstat(2).

source

pub fn fs_lstat_sync(&self, path: &str) -> Result<Stat, Box<dyn Error>>

Equivalent to lstat(2).

source

pub fn fs_statfs<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to statfs(2). On success, FsReq::statfs() will return a StatFs

Note: Any fields in the resulting StatFs that are not supported by the underlying operating system are set to zero.

source

pub fn fs_statfs_sync(&self, path: &str) -> Result<StatFs, Box<dyn Error>>

Equivalent to statfs(2). On success, FsReq::statfs() will return a StatFs

Note: Any fields in the resulting StatFs that are not supported by the underlying operating system are set to zero.

source

pub fn fs_rename<CB: Into<FsCB<'static>>>( &self, path: &str, new_path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to rename(2).

source

pub fn fs_rename_sync( &self, path: &str, new_path: &str ) -> Result<usize, Box<dyn Error>>

Equivalent to rename(2).

source

pub fn fs_fsync<CB: Into<FsCB<'static>>>( &self, file: File, cb: CB ) -> Result<FsReq>

Equivalent to fsync(2).

Note: For AIX, uv_fs_fsync returns UV_EBADF on file descriptors referencing non regular files.

source

pub fn fs_fsync_sync(&self, file: File) -> Result<usize>

Equivalent to fsync(2).

Note: For AIX, uv_fs_fsync returns UV_EBADF on file descriptors referencing non regular files.

source

pub fn fs_fdatasync<CB: Into<FsCB<'static>>>( &self, file: File, cb: CB ) -> Result<FsReq>

Equivalent to fdatasync(2).

source

pub fn fs_fdatasync_sync(&self, file: File) -> Result<usize>

Equivalent to fdatasync(2).

source

pub fn fs_ftruncate<CB: Into<FsCB<'static>>>( &self, file: File, offset: i64, cb: CB ) -> Result<FsReq>

Equivalent to ftruncate(2).

source

pub fn fs_ftruncate_sync(&self, file: File, offset: i64) -> Result<usize>

Equivalent to ftruncate(2).

source

pub fn fs_copyfile<CB: Into<FsCB<'static>>>( &self, path: &str, new_path: &str, flags: FsCopyFlags, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Copies a file from path to new_path. Supported flags are described below.

  • EXCL: If present, fs_copyfile() will fail with EEXIST if the destination path already exists. The default behavior is to overwrite the destination if it exists.
  • FICLONE: If present, fs_copyfile() will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, or an error occurs while attempting to use copy-on-write, a fallback copy mechanism based on fs_sendfile() is used.
  • FICLONE_FORCE: If present, fs_copyfile() will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, or an error occurs while attempting to use copy-on-write, then an error is returned.

Warning: If the destination path is created, but an error occurs while copying the data, then the destination path is removed. There is a brief window of time between closing and removing the file where another process could access the file.

source

pub fn fs_copyfile_sync( &self, path: &str, new_path: &str, flags: FsCopyFlags ) -> Result<usize, Box<dyn Error>>

Copies a file from path to new_path. Supported flags are described below.

  • EXCL: If present, fs_copyfile() will fail with EEXIST if the destination path already exists. The default behavior is to overwrite the destination if it exists.
  • FICLONE: If present, fs_copyfile() will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, or an error occurs while attempting to use copy-on-write, a fallback copy mechanism based on fs_sendfile() is used.
  • FICLONE_FORCE: If present, fs_copyfile() will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, or an error occurs while attempting to use copy-on-write, then an error is returned.

Warning: If the destination path is created, but an error occurs while copying the data, then the destination path is removed. There is a brief window of time between closing and removing the file where another process could access the file.

source

pub fn fs_sendfile<CB: Into<FsCB<'static>>>( &self, out_file: File, in_file: File, offset: i64, len: usize, cb: CB ) -> Result<FsReq>

Limited equivalent to sendfile(2).

source

pub fn fs_sendfile_sync( &self, out_file: File, in_file: File, offset: i64, len: usize ) -> Result<usize>

Limited equivalent to sendfile(2).

source

pub fn fs_access<CB: Into<FsCB<'static>>>( &self, path: &str, mode: FsAccessFlags, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to access(2) on Unix. Windows uses GetFileAttributesW().

source

pub fn fs_access_sync( &self, path: &str, mode: FsAccessFlags ) -> Result<usize, Box<dyn Error>>

Equivalent to access(2) on Unix. Windows uses GetFileAttributesW().

source

pub fn fs_chmod<CB: Into<FsCB<'static>>>( &self, path: &str, mode: FsModeFlags, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to chmod(2).

source

pub fn fs_chmod_sync( &self, path: &str, mode: FsModeFlags ) -> Result<usize, Box<dyn Error>>

Equivalent to chmod(2).

source

pub fn fs_fchmod<CB: Into<FsCB<'static>>>( &self, file: File, mode: FsModeFlags, cb: CB ) -> Result<FsReq>

Equivalent to fchmod(2).

source

pub fn fs_fchmod_sync(&self, file: File, mode: FsModeFlags) -> Result<usize>

Equivalent to fchmod(2).

source

pub fn fs_utime<CB: Into<FsCB<'static>>>( &self, path: &str, atime: f64, mtime: f64, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to utime(2).

Note: AIX: This function only works for AIX 7.1 and newer. It can still be called on older versions but will return ENOSYS.

source

pub fn fs_utime_sync( &self, path: &str, atime: f64, mtime: f64 ) -> Result<usize, Box<dyn Error>>

Equivalent to utime(2).

Note: AIX: This function only works for AIX 7.1 and newer. It can still be called on older versions but will return ENOSYS.

source

pub fn fs_futime<CB: Into<FsCB<'static>>>( &self, file: File, atime: f64, mtime: f64, cb: CB ) -> Result<FsReq>

Equivalent to futimes(3) respectively.

Note: AIX: This function only works for AIX 7.1 and newer. It can still be called on older versions but will return ENOSYS.

source

pub fn fs_futime_sync( &self, file: File, atime: f64, mtime: f64 ) -> Result<usize>

Equivalent to futimes(3) respectively.

Note: AIX: This function only works for AIX 7.1 and newer. It can still be called on older versions but will return ENOSYS.

Equivalent to link(2).

Equivalent to link(2).

Equivalent to symlink(2).

Note: On Windows the flags parameter can be specified to control how the symlink will be created:

  • UV_FS_SYMLINK_DIR: indicates that path points to a directory.
  • UV_FS_SYMLINK_JUNCTION: request that the symlink is created using junction points.

Equivalent to symlink(2).

Note: On Windows the flags parameter can be specified to control how the symlink will be created:

  • UV_FS_SYMLINK_DIR: indicates that path points to a directory.
  • UV_FS_SYMLINK_JUNCTION: request that the symlink is created using junction points.

Equivalent to readlink(2). The path can be read from FsReq::real_path()

Equivalent to readlink(2).

source

pub fn fs_realpath<CB: Into<FsCB<'static>>>( &self, path: &str, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandle. The path can be read from FsReq::real_path()

Warning: This function has certain platform-specific caveats that were discovered when used in Node.

  • macOS and other BSDs: this function will fail with ELOOP if more than 32 symlinks are found while resolving the given path. This limit is hardcoded and cannot be sidestepped.
  • Windows: while this function works in the common case, there are a number of corner cases where it doesn’t:
    • Paths in ramdisk volumes created by tools which sidestep the Volume Manager (such as ImDisk) cannot be resolved.
    • Inconsistent casing when using drive letters.
    • Resolved path bypasses subst’d drives.

While this function can still be used, it’s not recommended if scenarios such as the above need to be supported.

Note: This function is not implemented on Windows XP and Windows Server 2003. On these systems, ENOSYS is returned.

source

pub fn fs_realpath_sync(&self, path: &str) -> Result<String, Box<dyn Error>>

Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandle.

Warning: This function has certain platform-specific caveats that were discovered when used in Node.

  • macOS and other BSDs: this function will fail with ELOOP if more than 32 symlinks are found while resolving the given path. This limit is hardcoded and cannot be sidestepped.
  • Windows: while this function works in the common case, there are a number of corner cases where it doesn’t:
    • Paths in ramdisk volumes created by tools which sidestep the Volume Manager (such as ImDisk) cannot be resolved.
    • Inconsistent casing when using drive letters.
    • Resolved path bypasses subst’d drives.

While this function can still be used, it’s not recommended if scenarios such as the above need to be supported.

Note: This function is not implemented on Windows XP and Windows Server 2003. On these systems, ENOSYS is returned.

source

pub fn fs_chown<CB: Into<FsCB<'static>>>( &self, path: &str, uid: Uid, gid: Gid, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to chown(2)

Note: This functions are not implemented on Windows.

source

pub fn fs_chown_sync( &self, path: &str, uid: Uid, gid: Gid ) -> Result<usize, Box<dyn Error>>

Equivalent to chown(2)

Note: This functions are not implemented on Windows.

source

pub fn fs_fchown<CB: Into<FsCB<'static>>>( &self, file: File, uid: Uid, gid: Gid, cb: CB ) -> Result<FsReq>

Equivalent to fchown(2)

Note: This functions are not implemented on Windows.

source

pub fn fs_fchown_sync(&self, file: File, uid: Uid, gid: Gid) -> Result<usize>

Equivalent to fchown(2)

Note: This functions are not implemented on Windows.

source

pub fn fs_lchown<CB: Into<FsCB<'static>>>( &self, path: &str, uid: Uid, gid: Gid, cb: CB ) -> Result<FsReq, Box<dyn Error>>

Equivalent to lchown(2)

Note: This functions are not implemented on Windows.

source

pub fn fs_lchown_sync( &self, path: &str, uid: Uid, gid: Gid ) -> Result<usize, Box<dyn Error>>

Equivalent to lchown(2)

Note: This functions are not implemented on Windows.

source§

impl Loop

source

pub fn async<CB: Into<AsyncCB<'static>>>(&self, cb: CB) -> Result<AsyncHandle>

Create and initialize a new async handle

source§

impl Loop

source

pub fn check(&self) -> Result<CheckHandle>

Create and initialize a new check handle

source§

impl Loop

source

pub fn fs_event(&self) -> Result<FsEventHandle>

Create and initialize a fs event handle

source§

impl Loop

source

pub fn fs_poll(&self) -> Result<FsPollHandle>

Create and initialize a fs poll handle

source§

impl Loop

source

pub fn idle(&self) -> Result<IdleHandle>

Create and initialize a new idle handle

source§

impl Loop

source

pub fn poll(&self, fd: File) -> Result<PollHandle>

Create and initialize a new poll handle using a file descriptor

source

pub fn poll_socket(&self, socket: Socket) -> Result<PollHandle>

Create and initialize a new poll handle using a socket descriptor. On Unix this is identical to poll(). On windows it takes a SOCKET handle.

source§

impl Loop

source

pub fn prepare(&self) -> Result<PrepareHandle>

Create and initialize a new prepare handle

source§

impl Loop

source

pub fn spawn_process( &self, options: ProcessOptions<'_> ) -> Result<ProcessHandle, Box<dyn Error>>

Create a new process handle and spawn the process

source§

impl Loop

source

pub fn signal(&self) -> Result<SignalHandle>

Create and initialize a new signal handle

source§

impl Loop

source

pub fn timer(&self) -> Result<TimerHandle>

Create and initialize a new timer handle

source§

impl Loop

source

pub fn pipe(&self, ipc: bool) -> Result<PipeHandle>

Create and initialize a pipe handle. The ipc argument is a boolean to indicate if this pipe will be used for handle passing between processes (which may change the bytes on the wire). Only a connected pipe that will be passing the handles should have this flag set, not the listening pipe that accept() is called on.

source§

impl Loop

source

pub fn tcp(&self) -> Result<TcpHandle>

Initialize the handle. No socket is created as of yet.

source§

impl Loop

source

pub fn tty(&self, fd: i32) -> Result<TtyHandle>

Initialize a new TTY stream with the given file descriptor. Usually the file descriptor will be:

0 = stdin 1 = stdout 2 = stderr

On Unix this function will determine the path of the fd of the terminal using ttyname_r(3), open it, and use it if the passed file descriptor refers to a TTY. This lets libuv put the tty in non-blocking mode without affecting other processes that share the tty.

This function is not thread safe on systems that don’t support ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and Solaris.

Note: If reopening the TTY fails, libuv falls back to blocking writes.

source§

impl Loop

source

pub fn udp(&self) -> Result<UdpHandle>

Initialize a new UDP handle. The actual socket is created lazily.

source§

impl Loop

source

pub fn getaddrinfo<CB: Into<GetAddrInfoCB<'static>>>( &self, node: Option<&str>, service: Option<&str>, hints: Option<AddrInfo>, cb: CB ) -> Result<GetAddrInfoReq, Box<dyn Error>>

Asynchronous getaddrinfo(3).

Either node or service may be None but not both.

hints is a AddrInfo with additional address type constraints, or None. Consult man -s 3 getaddrinfo for more details.

source

pub fn getaddrinfo_sync( &self, node: Option<&str>, service: Option<&str>, hints: Option<AddrInfo> ) -> Result<Vec<AddrInfo>, Box<dyn Error>>

Synchronous getaddrinfo(3).

Either node or service may be None but not both.

hints is a AddrInfo with additional address type constraints, or None. Consult man -s 3 getaddrinfo for more details.

Returns an iterator over resulting AddrInfo structs.

source§

impl Loop

source

pub fn getnameinfo<CB: Into<GetNameInfoCB<'static>>>( &self, addr: &SocketAddr, flags: u32, cb: CB ) -> Result<GetNameInfoReq, Box<dyn Error>>

Asynchronous getnameinfo(3).

If successful, the callback will get called sometime in the future with the lookup result. Consult man -s 3 getnameinfo for more details.

flags is the bitwise OR of NI_* constants

source

pub fn getnameinfo_sync( &self, addr: &SocketAddr, flags: u32 ) -> Result<(String, String), Box<dyn Error>>

Synchronous getnameinfo(3).

If successful, will return a tuple of (host, service) Strings.

flags is the bitwise OR of NI_* constants

source§

impl Loop

source

pub fn random<CB: Into<RandomCB<'static>>>( &self, buflen: usize, flags: u32, cb: CB ) -> Result<RandomReq>

Fill a buf with exactly buflen cryptographically strong random bytes acquired from the system CSPRNG. flags is reserved for future extension and must currently be 0.

Short reads are not possible. When less than buflen random bytes are available, a non-zero error value is returned or passed to the callback.

The asynchronous version may not ever finish when the system is low on entropy.

Sources of entropy:

source

pub fn random_sync(buflen: usize, flags: u32) -> Result<Vec<u8>>

Fill a buf with exactly buflen cryptographically strong random bytes acquired from the system CSPRNG. flags is reserved for future extension and must currently be 0.

Short reads are not possible. When less than buflen random bytes are available, a non-zero error value is returned or passed to the callback.

The synchronous version may block indefinitely when not enough entropy is available.

Sources of entropy:

source§

impl Loop

source

pub fn queue_work<CB: Into<WorkCB<'static>>, ACB: Into<AfterWorkCB<'static>>>( &self, work_cb: CB, after_work_cb: ACB ) -> Result<WorkReq>

Initializes a work request which will run the given work_cb in a thread from the threadpool. Once work_cb is completed, after_work_cb will be called on the loop thread.

This request can be cancelled with Req::cancel().

Trait Implementations§

source§

impl Clone for Loop

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for Loop

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Loop

§

impl !Send for Loop

§

impl !Sync for Loop

§

impl Unpin for Loop

§

impl UnwindSafe for Loop

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.