Sign in

    uv

    MoonBit binding to libuv

    Download zip
    Version
    0.10.0
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    1K

    #tonyfettes/uv

    This is a MoonBit binding to the libuv library.

    #Quickstart

    1. Add this module as a dependency to your MoonBit project.

      moon update moon add tonyfettes/uv

    2. Import tonyfettes/uv package where you need it.

      { "import": [ "tonyfettes/uv" ] }

    3. Use the tonyfettes/uv package in your MoonBit project.

      fn main {
      try {
      let uv = @uv.Loop::new()
      let options = @uv.ProcessOptions::new(
      "moon",
      ["moon", "version"],
      fn(process, exit_status, term_signal) {
      println(
      "Process exited with status \{exit_status} and signal \{term_signal}",
      )
      process.close(fn(_) { })
      },
      )
      let process = uv.spawn(options)
      println("Launched process with ID \{(process).pid()}")
      uv.run(Default)
      uv.stop()
      uv.close()
      } catch {
      error => println("Error: \{error}")
      }
      }

    Cancelable

    pub trait Cancelable : ToReq {
    cancel(Self) -> Unit raise Errno
    }

    Share

    pub trait Share {
    share(Self) -> Self
    }

    Shares an object safely between threads.

    In MoonBit, the default reference counting (RC) for objects is not atomic, so it is not safe to share most objects directly between threads.

    To enable safe sharing, we use a separate atomic reference counter (ARC) stored alongside the actual object data. The MoonBit object itself is managed by non-atomic RC, but the shared payload is managed by ARC.

    When you want to share an object:
    • The MoonBit object holds a pointer to a heap-allocated block containing both the ARC and the payload (e.g., a mutex or thread handle).
    • Copying the MoonBit object only copies the pointer; the ARC is incremented atomically (guarded by a mutex if needed).
    • When a copy is dropped, the ARC is decremented atomically. When ARC reaches zero, the payload is freed.

    Example: uv_thread_t stores an arc field and a uv_mutex_t object in a heap-allocated block. All increments/decrements of arc are protected by the mutex to ensure thread safety.

    Diagram: (thread 0) (thread 1) +--------+ +--------+ | rc (M) | | rc (M) | +--------+ +--------+ \ / ---> +---------+ <---/ | arc (F) | +---------+ | mutex | +---------+ | payload | +----+----+

    The Share trait provides a share method to allow implementor of this trait to create a new MoonBit object pointing to the same shared payload, incrementing the ARC safely.

    ToHandle

    pub trait ToHandle {
    to_handle(Self) -> Handle
    of_handle(Handle) -> Self
    close(Self, (Self) -> Unit) -> Unit
    is_closing(Self) -> Bool
    loop_(Self) -> Loop
    }

    ToNtbs

    trait ToNtbs

    Convertible to null-terminated byte strings (NTBS).
    impl ToNtbs for String
    impl ToNtbs for Bytes
    impl ToNtbs for View

    ToReq

    pub trait ToReq {
    to_req(Self) -> Req
    }

    ToSockaddr

    pub trait ToSockaddr {
    to_sockaddr(self : Self) -> Sockaddr
    ip_name(self : Self) -> String raise Errno
    }

    ToStream

    pub trait ToStream : ToHandle {
    to_stream(Self) -> Stream
    of_stream(Stream) -> Self
    read_start(Self, (Self, Int) ->
    View
    , (Self, Int,
    View
    ) -> Unit, (Self, Errno) -> Unit) -> Unit raise Errno
    read_stop(Self) -> Unit raise Errno
    write(Self, Array[
    View
    ], () -> Unit, (Errno) -> Unit) -> Unit raise Errno
    listen(Self, Int, (Self) -> Unit, (Self, Errno) -> Unit) -> Unit raise Errno
    is_readable(Self) -> Bool
    is_writable(Self) -> Bool
    shutdown(Self, () -> Unit, (Errno) -> Unit) -> Shutdown raise Errno
    }

    AccessFlags

    type AccessFlags

    AccessFlags::new

    fn AccessFlags::new(read~ : Bool = .., write~ : Bool = .., execute~ : Bool = ..) -> AccessFlags

    AddrInfo

    type AddrInfo

    AddrInfo::addr

    fn AddrInfo::addr(self : AddrInfo) -> Sockaddr

    AddrInfo::canonname

    fn AddrInfo::canonname(self : AddrInfo) -> String?

    AddrInfo::family

    fn AddrInfo::family(self : AddrInfo) -> AddressFamily raise Errno

    AddrInfo::protocol

    fn AddrInfo::protocol(self : AddrInfo) -> Protocol raise Errno

    AddrInfo::socktype

    fn AddrInfo::socktype(self : AddrInfo) -> SockType raise Errno

    AddrInfoFlags

    type AddrInfoFlags

    AddrInfoFlags::new

    fn AddrInfoFlags::new(passive~ : Bool = .., canonname~ : Bool = .., numeric_host~ : Bool = .., numeric_serv~ : Bool = .., all~ : Bool = .., addrconfig~ : Bool = .., v4mapped~ : Bool = ..) -> AddrInfoFlags

    AddrInfoHints

    type AddrInfoHints

    AddrInfoHints::new

    fn AddrInfoHints::new(flags? : AddrInfoFlags, family? : AddressFamily, socktype? : SockType, protocol? : Protocol) -> AddrInfoHints

    AddressFamily

    pub enum AddressFamily {
    Inet
    Inet6
    }

    Represents the address family for network communication, specifying the format of network addresses.

    Constructors:

    • Inet : IPv4 address family
    • Inet6 : IPv6 address family

    Example:

    let ipv4 = AddressFamily::inet()
    let ipv6 = AddressFamily::inet6()
    inspect(ipv4, content="Inet")
    inspect(ipv6, content="Inet6")

    AddressFamily::inet

    AddressFamily::inet6

    Connect

    type Connect

    impl ToReq for Connect

    CopyFileFlags

    type CopyFileFlags

    CopyFileFlags::new

    fn CopyFileFlags::new(allow_exists~ : Bool = .., copy_on_write~ : CopyOnWrite = ..) -> CopyFileFlags

    CopyOnWrite

    pub(all) enum CopyOnWrite {
    False
    True
    Force
    }

    CpuInfo

    pub struct CpuInfo {
    model : String
    speed : Int
    cpu_times : CpuTimes
    }

    impl Show for CpuInfo
    impl ToJson for CpuInfo

    CpuTimes

    pub struct CpuTimes {
    user : UInt64
    nice : UInt64
    sys : UInt64
    idle : UInt64
    irq : UInt64
    }

    impl Show for CpuTimes
    impl ToJson for CpuTimes

    Dir

    type Dir

    Dirent

    pub struct Dirent {
    name : String
    type_ : DirentType
    }

    impl ToJson for Dirent

    Dirent::name

    fn Dirent::name(self : Dirent) -> String

    Dirent::type_

    fn Dirent::type_(self : Dirent) -> DirentType

    DirentType

    pub enum DirentType {
    Unknown
    File
    Dir
    Link
    Fifo
    Socket
    Char
    Block
    }

    Type of directory entry, indicating the file system object kind.
    impl Show for DirentType

    Environ

    type Environ

    Environ::iter2

    fn Environ::iter2(self : Environ) -> Iter2[String, String]

    Errno

    pub type! Errno Status

    impl Eq for Errno
    impl Hash for Errno
    impl Show for Errno

    File

    type File

    type Fs

    impl Cancelable for Fs
    impl ToReq for Fs

    FsEvent

    type FsEvent

    impl ToHandle for FsEvent

    FsEvent::get_path

    fn FsEvent::get_path(self : FsEvent) -> String raise Errno

    FsEvent::new

    fn FsEvent::new(self : Loop) -> FsEvent raise Errno

    FsEvent::start

    fn[ToNtbs : ToNtbs] FsEvent::start(self : FsEvent, path : ToNtbs, flags : FsEventFlags, event_cb : (FsEvent, String?, Array[FsEventType]) -> Unit, error_cb : (FsEvent, String?, Errno) -> Unit) -> Unit raise Errno

    FsEvent::stop

    fn FsEvent::stop(self : FsEvent) -> Unit raise Errno

    FsEventFlags

    type FsEventFlags

    FsEventFlags::new

    fn FsEventFlags::new(recursive~ : Bool = ..) -> FsEventFlags

    FsEventType

    pub enum FsEventType {
    Rename
    Change
    }

    impl Show for FsEventType

    GetAddrInfo

    type GetAddrInfo

    Gid

    type Gid

    Handle

    type Handle

    Handle::close

    fn Handle::close(self : Handle, cb : (Handle) -> Unit) -> Unit

    Handle::is_closing

    fn Handle::is_closing(self : Handle) -> Bool

    HandleType

    pub enum HandleType {
    Unknown
    Async
    Check
    FsEvent
    FsPoll
    Handle
    Idle
    Pipe
    Poll
    Prepare
    Process
    Stream
    Tcp
    Timer
    Tty
    Udp
    Signal
    File
    }

    impl Eq for HandleType
    impl Hash for HandleType

    Idle

    type Idle

    Handle for idle watchers in the libuv event loop.

    Idle watchers run their callbacks once per event loop iteration, right before the event loop blocks for I/O. They are useful for performing background tasks when the event loop is idle.

    Example:

    let uv = @uv.Loop::new()
    let idle = @uv.Idle::new(uv)
    idle.start(fn(_) {
    println("Idle callback running")
    idle.stop() catch {
    error => println("Error stopping idle watcher: \{error}")
    }
    idle.close(_ => ())
    })
    uv.run(Default)
    uv.close()
    impl ToHandle for Idle

    Idle::new

    fn Idle::new(self : Loop) -> Idle raise Errno

    Idle::start

    fn Idle::start(self : Idle, cb : (Idle) -> Unit) -> Unit raise Errno

    Idle::stop

    fn Idle::stop(self : Idle) -> Unit raise Errno

    Loop

    type Loop

    Loop::alive

    fn Loop::alive(uv : Loop) -> Bool

    Loop::close

    fn Loop::close(self : Loop) -> Unit raise Errno

    Closes the event loop and releases its associated resources.

    Parameters:

    • self : The event loop to close.

    Throws an error of type Errno if the loop cannot be closed properly, such as when there are still active handles or requests associated with the loop.

    Example:

    let uv = @uv.Loop::new()
    uv.close()

    Loop::fs_access

    fn[Ntbs : ToNtbs] Loop::fs_access(self : Loop, path : Ntbs, mode : AccessFlags, access_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_access_sync

    fn[Ntbs : ToNtbs] Loop::fs_access_sync(self : Loop, path : Ntbs, mode : AccessFlags) -> Unit raise Errno

    Loop::fs_close

    fn Loop::fs_close(self : Loop, file : File, close_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously closes a file descriptor.

    This function initiates a file close operation that will be handled asynchronously by the event loop. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • file : The file descriptor to close, typically obtained from fs_open or fs_open_sync.
    • close_cb : Success callback function that receives the filesystem request handle when the file is closed successfully.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid file descriptor or system resource exhaustion).

    Example:

    let uv = Loop::new()
    let file = uv.fs_open_sync("README.md", OpenFlags::read_only(), 0o644)
    uv.fs_close(
    file,
    fn() { println("File closed successfully") },
    fn(error) { println("Failed to close file: \{error}") }
    )
    |> ignore()
    uv.run(Default)
    uv.close()

    Loop::fs_close_sync

    fn Loop::fs_close_sync(self : Loop, file : File) -> Unit raise Errno

    Loop::fs_closedir

    fn Loop::fs_closedir(self : Loop, dir : Dir, closedir_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_copyfile

    fn[Ntbs : ToNtbs] Loop::fs_copyfile(self : Loop, path : Ntbs, new_path : Ntbs, flags : CopyFileFlags, copy_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_copyfile_sync

    fn[Ntbs : ToNtbs] Loop::fs_copyfile_sync(self : Loop, path : Ntbs, new_path : Ntbs, flags : CopyFileFlags) -> Unit raise Errno

    Loop::fs_fstat

    fn Loop::fs_fstat(self : Loop, file : File, fstat_cb : (Stat) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_ftruncate

    fn Loop::fs_ftruncate(self : Loop, file : File, length : Int64, k : () -> Unit, e : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_lstat

    fn[Ntbs : ToNtbs] Loop::fs_lstat(self : Loop, path : Ntbs, lstat_cb : (Stat) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_mkdir

    fn[Ntbs : ToNtbs] Loop::fs_mkdir(self : Loop, path : Ntbs, mode : Int, mkdir_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously creates a directory at the specified path with the given permissions.

    This function initiates a directory creation operation that will be handled asynchronously by the event loop. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • path : The directory path to create. Can be any type that implements ToNtbs (convertible to null-terminated byte string), such as String, Bytes, @string.View, or @bytes.View.
    • mode : The directory permissions to use when creating the directory (octal notation, e.g., 0o755).
    • mkdir_cb : Success callback function that receives the filesystem request handle when the directory is created successfully.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid parameters or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    let dir = "test/fixtures/doc-test-dir"
    uv.fs_mkdir(
    dir,
    0o755,
    fn() { println("Directory created successfully") },
    fn(error) {
    println("Failed to create directory: \{error} (expected)")
    }
    )
    |> ignore()
    uv.run(Default)
    uv.fs_rmdir_sync(dir)
    uv.close()

    Loop::fs_mkdir_sync

    fn[Ntbs : ToNtbs] Loop::fs_mkdir_sync(self : Loop, path : Ntbs, mode : Int) -> Unit raise Errno

    Synchronously creates a directory at the specified path with the given permissions.

    This function blocks the current thread until the directory creation operation completes. Unlike the asynchronous fs_mkdir function, this operation does not require callbacks and returns immediately upon completion or failure.

    Parameters:

    • self : The event loop instance to perform the operation on.
    • path : The directory path to create. Can be any type that implements ToNtbs (convertible to null-terminated byte string), such as String, Bytes, @string.View, or @bytes.View.
    • mode : The directory permissions to use when creating the directory (octal notation, e.g., 0o755).

    Throws an error of type Errno if the directory cannot be created (e.g., path already exists, insufficient permissions, or invalid path).

    Example:

    let uv = @uv.Loop::new()
    uv.fs_mkdir_sync("test/fixtures", 0o755) catch {
    error => println("Failed to create directory: \{error} (expected)")
    }
    uv.close()

    Loop::fs_mkdtemp

    fn[Ntbs : ToNtbs] Loop::fs_mkdtemp(self : Loop, template : Ntbs, mkdtemp_cb : (String) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_mkdtemp_sync

    fn[Ntbs : ToNtbs] Loop::fs_mkdtemp_sync(self : Loop, template : Ntbs) -> String raise Errno

    Loop::fs_mkstemp

    fn[Ntbs : ToNtbs] Loop::fs_mkstemp(self : Loop, template : Ntbs, mkstemp_cb : (String) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_mkstemp_sync

    fn[Ntbs : ToNtbs] Loop::fs_mkstemp_sync(self : Loop, template : Ntbs) -> String raise Errno

    Loop::fs_open

    fn[Ntbs : ToNtbs] Loop::fs_open(self : Loop, path : Ntbs, flags : OpenFlags, mode : Int, open_cb : (File) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously opens a file at the specified path with the given flags and mode.

    This function initiates a file open operation that will be handled asynchronously by the event loop. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • path : The file path to open. Can be any type that implements ToNtbs (convertible to null-terminated byte string), such as String, Bytes, @string.View, or @bytes.View.
    • flags : The file access mode and behavior flags. Use OpenFlags::read_only(), OpenFlags::write_only(), or OpenFlags::read_write() with optional parameters for additional behaviors like append, create, truncate, or exclusive access.
    • mode : The file permissions to use when creating a new file (octal notation, e.g., 0o644). This parameter is ignored if the file already exists.
    • open_cb : Success callback function that receives the filesystem request handle and the opened file descriptor when the operation succeeds.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid parameters or system resource exhaustion).

    Example:

    let uv = Loop::new()
    uv.fs_open(
    "README.md",
    OpenFlags::read_only(),
    0o644,
    (file) => uv.fs_close_sync(file) catch { _ => () },
    (error) => println("Failed to open file: \{error}"),
    )
    |> ignore()
    uv.run(Default)
    uv.close()

    Loop::fs_open_sync

    fn[Ntbs : ToNtbs] Loop::fs_open_sync(self : Loop, path : Ntbs, flags : OpenFlags, mode : Int) -> File raise Errno

    Synchronously opens a file at the specified path with the given flags and mode.

    This function blocks the current thread until the file open operation completes. Unlike the asynchronous fs_open function, this operation does not require callbacks and returns the file descriptor immediately upon successful completion.

    Parameters:

    • self : The event loop instance to perform the operation on.
    • path : The file path to open. Can be any type that implements ToNtbs (convertible to null-terminated byte string), such as String, Bytes, @string.View, or @bytes.View.
    • flags : The file access mode and behavior flags. Use OpenFlags::read_only(), OpenFlags::write_only(), or OpenFlags::read_write() with optional parameters for additional behaviors like append, create, truncate, or exclusive access.
    • mode : The file permissions to use when creating a new file (octal notation, e.g., 0o644). This parameter is ignored if the file already exists.

    Returns a File handle that can be used for subsequent file operations like reading, writing, or closing.

    Throws an error of type Errno if the file cannot be opened (e.g., file does not exist, insufficient permissions, invalid path, or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    let file = uv.fs_open_sync("README.md", @uv.OpenFlags::read_only(), 0o644)
    uv.fs_close_sync(file)
    uv.close()

    Loop::fs_opendir

    fn[Ntbs : ToNtbs] Loop::fs_opendir(self : Loop, path : Ntbs, opendir_cb : (Dir) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_read

    fn Loop::fs_read(self : Loop, file : File, bufs : Array[
    View
    ], offset~ : Int64 = .., read_cb : (Int) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously reads data from a file into multiple buffers.

    This function initiates a read operation that will be handled asynchronously by the event loop. The data is read from the file into the provided array of byte views, which can be used for scatter-gather I/O operations. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • file : The file descriptor to read from, typically obtained from fs_open or fs_open_sync.
    • bufs : An array of byte views that will receive the data read from the file. The views define both the memory locations and the amount of data to read into each buffer.
    • offset : The file position to start reading from. If -1 (default), reads from the current file position. Otherwise, reads from the specified absolute position in the file.
    • read_cb : Success callback function that receives the filesystem request handle and the number of bytes actually read when the operation succeeds.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid file descriptor or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    uv.fs_read(
    @uv.stdin(),
    [Bytes::make(100, 0)],
    fn(bytes_read) { println("Read \{bytes_read} bytes") },
    fn(error) { println("Error: \{error}") }
    )
    |> ignore()
    uv.run(Default)
    uv.close()

    Loop::fs_read_sync

    fn Loop::fs_read_sync(self : Loop, file : File, bufs : Array[
    View
    ], offset~ : Int64 = ..) -> Int raise Errno

    Loop::fs_readdir

    fn Loop::fs_readdir(self : Loop, dir : Dir, n : Int, readdir_cb : (Array[Dirent]) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_realpath

    fn[Ntbs : ToNtbs] Loop::fs_realpath(self : Loop, path : Ntbs, path_cb : (String) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously resolves a file path to its absolute canonical form.

    This function initiates a path resolution operation that will be handled asynchronously by the event loop. The resolved path eliminates symbolic links, relative path components (like . and ..), and redundant separators to produce an absolute canonical path. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • path : The file path to resolve. Can be any type that implements ToNtbs (convertible to null-terminated byte string), such as String, Bytes, @string.View, or @bytes.View.
    • path_cb : Success callback function that receives the filesystem request handle and the resolved absolute path when the operation succeeds.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid parameters or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    uv.fs_realpath(
    "test/fixtures/example.txt",
    realpath => println("Resolved: \{realpath}"),
    error => println("Failed to resolve path: \{error}")
    )
    |> ignore()
    uv.run(Default)
    uv.close()

    Loop::fs_realpath_sync

    fn[Ntbs : ToNtbs] Loop::fs_realpath_sync(self : Loop, path : Ntbs) -> String raise Errno

    Loop::fs_rename

    fn[Ntbs : ToNtbs] Loop::fs_rename(self : Loop, path : Ntbs, new_path : Ntbs, rename_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_rmdir

    fn[Ntbs : ToNtbs] Loop::fs_rmdir(self : Loop, path : Ntbs, rmdir_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_rmdir_sync

    fn[Ntbs : ToNtbs] Loop::fs_rmdir_sync(self : Loop, path : Ntbs) -> Unit raise Errno

    Loop::fs_scandir

    fn[Ntbs : ToNtbs] Loop::fs_scandir(self : Loop, path : Ntbs, flags : Int, scandir_cb : (Scandir) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_scandir_sync

    fn[Ntbs : ToNtbs] Loop::fs_scandir_sync(self : Loop, path : Ntbs, flags : Int) -> Scandir raise Errno

    Loop::fs_stat

    fn[Ntbs : ToNtbs] Loop::fs_stat(self : Loop, path : Ntbs, stat_cb : (Stat) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Loop::fs_stat_sync

    fn[Ntbs : ToNtbs] Loop::fs_stat_sync(self : Loop, path : Ntbs) -> Stat raise Errno

    fn[Ntbs : ToNtbs] Loop::fs_unlink(self : Loop, path : Ntbs, k : () -> Unit, e : (Error) -> Unit) -> Fs raise Errno

    fn[Ntbs : ToNtbs] Loop::fs_unlink_sync(self : Loop, path : Ntbs) -> Unit raise Errno

    Loop::fs_write

    fn Loop::fs_write(self : Loop, file : File, bufs : Array[
    View
    ], offset~ : Int64 = .., write_cb : (Int) -> Unit, error_cb : (Errno) -> Unit) -> Fs raise Errno

    Asynchronously writes data from multiple buffers to a file.

    This function initiates a write operation that will be handled asynchronously by the event loop. The data is written from the provided array of byte views to the file, which can be used for gather I/O operations. When the operation completes, either the success callback or error callback will be invoked depending on the result.

    Parameters:

    • self : The event loop instance to schedule the operation on.
    • file : The file descriptor to write to, typically obtained from fs_open or fs_open_sync.
    • bufs : An array of byte views containing the data to write to the file. The views define both the memory locations and the amount of data to write from each buffer.
    • offset : The file position to start writing to. If -1 (default), writes to the current file position. Otherwise, writes to the specified absolute position in the file.
    • write_cb : Success callback function that receives the filesystem request handle and the number of bytes actually written when the operation succeeds.
    • error_cb : Error callback function that receives the filesystem request handle and the error code when the operation fails.

    Throws an error of type Errno if the operation cannot be initiated (e.g., invalid file descriptor or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    let path = "test/fixtures/doc-test.txt"
    let file = uv.fs_open_sync(
    path,
    @uv.OpenFlags::write_only(create=true),
    0o644
    )
    let data : Bytes = "Hello, World!"
    uv.fs_write(
    file,
    [data],
    fn(written) { println("Wrote \{written} bytes") },
    fn(error) { println("Error: \{error}") }
    )
    |> ignore()
    uv.run(Default)
    uv.fs_close_sync(file)
    uv.fs_unlink_sync(path)
    uv.close()

    Loop::fs_write_sync

    fn Loop::fs_write_sync(self : Loop, file : File, bufs : Array[
    View
    ], offset~ : Int64 = ..) -> Unit raise Errno

    Synchronously writes data from multiple buffers to a file.

    This function blocks the current thread until the write operation completes. Unlike the asynchronous fs_write function, this operation does not require callbacks and returns immediately upon successful completion or failure.

    Parameters:

    • self : The event loop instance to perform the operation on.
    • file : The file descriptor to write to, typically obtained from fs_open or fs_open_sync.
    • bufs : An array of byte views containing the data to write to the file. The views define both the memory locations and the amount of data to write from each buffer.
    • offset : The file position to start writing to. If -1 (default), writes to the current file position. Otherwise, writes to the specified absolute position in the file.

    Throws an error of type Errno if the file cannot be written to (e.g., invalid file descriptor, insufficient permissions, disk full, or system resource exhaustion).

    Example:

    let uv = @uv.Loop::new()
    let path = "test/fixtures/doc-test-sync.txt"
    let file = uv.fs_open_sync(
    path,
    @uv.OpenFlags::write_only(create=true),
    0o644
    )
    let data : Bytes = "Hello, World!"
    uv.fs_write_sync(file, [data])
    uv.fs_close_sync(file)
    uv.fs_unlink_sync(path)
    uv.close()

    Loop::getaddrinfo

    fn[Node : ToNtbs, Service : ToNtbs] Loop::getaddrinfo(self : Loop, getaddrinfo_cb : (GetAddrInfo, Iter[AddrInfo]) -> Unit, error_cb : (GetAddrInfo, Errno) -> Unit, node : Node, service : Service, hints? : AddrInfoHints) -> Unit raise Errno

    Loop::new

    fn Loop::new() -> Loop raise Errno

    Creates a new event loop instance.

    Returns a new event loop that can be used for asynchronous I/O operations.

    Throws an error of type Errno if the loop initialization fails due to system resource constraints or other platform-specific issues.

    Example:

    let uv = @uv.Loop::new()
    uv.close()

    Loop::print_all_handles

    fn Loop::print_all_handles(self : Loop, file : File) -> Unit

    Loop::queue_work

    fn Loop::queue_work(self : Loop, work_cb : () -> Unit, after_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Work raise Errno

    Loop::random

    fn Loop::random(self : Loop, buffer :
    View
    , flags : Int, random_cb : (Random,
    View
    ) -> Unit, error_cb : (Random, Errno) -> Unit) -> Unit raise Errno

    Loop::run

    fn Loop::run(self : Loop, mode : RunMode) -> Unit raise Errno

    Runs the event loop with the specified mode.

    Parameters:

    • self : The event loop to run.
    • mode : The run mode that determines how the loop executes. Can be Default (runs until no more active handles), Once (runs once and returns), or NoWait (polls for I/O once but doesn't block).

    Throws an error of type Errno if the loop fails to run properly.

    Example:

    let uv = @uv.Loop::new()
    uv.run(Default)
    uv.close()

    Loop::spawn

    fn Loop::spawn(self : Loop, options : ProcessOptions) -> Process raise Errno

    Loop::stop

    fn Loop::stop(self : Loop) -> Unit

    Loop::walk

    fn Loop::walk(self : Loop, walk_cb : (Handle) -> Unit) -> Unit

    Mutex

    type Mutex

    impl Share for Mutex

    Mutex::lock

    fn Mutex::lock(self : Mutex) -> Unit

    Mutex::new

    fn Mutex::new() -> Mutex raise Errno

    Mutex::trylock

    fn Mutex::trylock(self : Mutex) -> Unit raise Errno

    Mutex::unlock

    fn Mutex::unlock(self : Mutex) -> Unit

    OpenFlags

    type OpenFlags

    OpenFlags::read_only

    fn OpenFlags::read_only() -> OpenFlags

    Creates file open flags for read-only access.

    Returns an OpenFlags instance configured for read-only file access. Files opened with these flags can only be read from, not written to or modified.

    Example:

    let uv = @uv.Loop::new()
    let flags = @uv.OpenFlags::read_only()
    let file = uv.fs_open_sync("README.md", flags, 0o644)
    uv.fs_close_sync(file)
    uv.close()

    OpenFlags::read_write

    fn OpenFlags::read_write(append~ : Bool = .., create~ : Bool = .., truncate~ : Bool = .., exclusive~ : Bool = ..) -> OpenFlags

    Creates file open flags for read-write access with configurable behaviors.

    Parameters:

    • append : Whether to append to the file instead of overwriting. When true, writes will be positioned at the end of the file. Defaults to false.
    • create : Whether to create the file if it doesn't exist. When true, a new file will be created if the specified path doesn't exist. Defaults to false.
    • truncate : Whether to truncate the file to zero length when opening. When true, any existing content will be discarded. Defaults to false.
    • exclusive : Whether to fail if the file already exists when creating. When true and create is also true, the operation will fail if the file already exists. Defaults to false.

    Returns an OpenFlags instance configured for read-write access with the specified behaviors.

    Example:

    let uv = @uv.Loop::new()
    // Create a new file for reading and writing, fail if it exists
    let flags = @uv.OpenFlags::read_write(create=true, exclusive=true)
    let path = "new_file.txt"
    let file = uv.fs_open_sync(path, flags, 0o644)
    uv.fs_close_sync(file)
    uv.fs_unlink_sync(path)
    uv.close()

    OpenFlags::write_only

    fn OpenFlags::write_only(append~ : Bool = .., create~ : Bool = .., truncate~ : Bool = .., exclusive~ : Bool = ..) -> OpenFlags

    Creates file open flags for write-only access with configurable behaviors.

    Parameters:

    • append : Whether to append to the file instead of overwriting. When true, writes will be positioned at the end of the file. Defaults to false.
    • create : Whether to create the file if it doesn't exist. When true, a new file will be created if the specified path doesn't exist. Defaults to false.
    • truncate : Whether to truncate the file to zero length when opening. When true, any existing content will be discarded. Defaults to false.
    • exclusive : Whether to fail if the file already exists when creating. When true and create is also true, the operation will fail if the file already exists. Defaults to false.

    Returns an OpenFlags instance configured for write-only access with the specified behaviors.

    Example:

    let uv = @uv.Loop::new()
    // Create a new file for writing, truncate if it exists
    let flags = @uv.OpenFlags::write_only(create=true, truncate=true)
    let path = "output.txt"
    let file = uv.fs_open_sync(path, flags, 0o644)
    uv.fs_close_sync(file)
    uv.fs_unlink_sync(path)
    uv.close()

    Pipe

    type Pipe

    impl ToHandle for Pipe
    impl ToStream for Pipe

    Pipe::bind

    fn[Ntbs : ToNtbs] Pipe::bind(self : Pipe, name : Ntbs, flags : PipeBindFlags) -> Unit raise Errno

    Pipe::new

    fn Pipe::new(self : Loop, ipc~ : Bool = ..) -> Pipe raise Errno

    Pipe::open

    fn Pipe::open(self : Pipe, file : File) -> Unit raise Errno

    Pipe::pending_count

    fn Pipe::pending_count(self : Pipe) -> UInt

    Pipe::pending_type

    fn Pipe::pending_type(self : Pipe) -> HandleType

    Pipe::to_handle

    fn Pipe::to_handle(self : Pipe) -> Handle

    Pipe::to_stream

    fn Pipe::to_stream(self : Pipe) -> Stream

    PipeBindFlags

    type PipeBindFlags

    PipeBindFlags::new

    fn PipeBindFlags::new(truncate~ : Bool = ..) -> PipeBindFlags

    Process

    type Process

    impl ToHandle for Process

    Process::kill

    fn Process::kill(self : Process, signum : Signum) -> Unit raise Errno

    Process::pid

    fn Process::pid(self : Process) -> Int

    ProcessOptions

    type ProcessOptions

    ProcessOptions::new

    Protocol

    pub enum Protocol {
    Tcp
    Udp
    }

    impl Show for Protocol

    Protocol::tcp

    fn Protocol::tcp() -> Protocol

    Protocol::udp

    fn Protocol::udp() -> Protocol

    Random

    type Random

    Req

    type Req

    RunMode

    pub(all) enum RunMode {
    Default
    Once
    NoWait
    }

    Scandir

    type Scandir

    Scandir::next

    fn Scandir::next(self : Scandir) -> Dirent raise Errno

    Shutdown

    type Shutdown

    impl ToReq for Shutdown

    Signal

    type Signal

    Signal::new

    fn Signal::new(self : Loop) -> Signal raise Errno

    Signal::start

    fn Signal::start(self : Signal, cb : (Signal, Signum) -> Unit, signum : Signum) -> Unit raise Errno

    Signal::stop

    fn Signal::stop(self : Signal) -> Unit raise Errno

    Signum

    type Signum

    Signum::sigabrt

    fn Signum::sigabrt() -> Signum

    Signum::sighup

    fn Signum::sighup() -> Signum

    Signum::sigint

    fn Signum::sigint() -> Signum

    Signum::sigpipe

    fn Signum::sigpipe() -> Signum raise Errno

    Signum::sigquit

    fn Signum::sigquit() -> Signum

    Signum::sigterm

    fn Signum::sigterm() -> Signum

    Signum::sigwinch

    fn Signum::sigwinch() -> Signum

    SockType

    type SockType

    impl Show for SockType

    SockType::datagram

    fn SockType::datagram() -> SockType

    SockType::dgram

    fn SockType::dgram() -> SockType

    SockType::raw

    fn SockType::raw() -> SockType

    SockType::stream

    fn SockType::stream() -> SockType

    Sockaddr

    type Sockaddr

    SockaddrIn

    type SockaddrIn

    SockaddrIn6

    type SockaddrIn6

    Stat

    type Stat

    Stat::atim_nsec

    fn Stat::atim_nsec(self : Stat) -> Int64

    Stat::atim_sec

    fn Stat::atim_sec(self : Stat) -> Int64

    Stat::birthtim_nsec

    fn Stat::birthtim_nsec(self : Stat) -> Int64

    Stat::birthtim_sec

    fn Stat::birthtim_sec(self : Stat) -> Int64

    Stat::blksize

    fn Stat::blksize(self : Stat) -> UInt64

    Stat::blocks

    fn Stat::blocks(self : Stat) -> UInt64

    Stat::ctim_nsec

    fn Stat::ctim_nsec(self : Stat) -> Int64

    Stat::ctim_sec

    fn Stat::ctim_sec(self : Stat) -> Int64

    Stat::dev

    fn Stat::dev(self : Stat) -> UInt64

    Stat::flags

    fn Stat::flags(self : Stat) -> UInt64

    Stat::gen

    fn Stat::gen(self : Stat) -> UInt64

    Stat::gid

    fn Stat::gid(self : Stat) -> UInt64

    Stat::ino

    fn Stat::ino(self : Stat) -> UInt64

    Stat::is_block_device

    fn Stat::is_block_device(self : Stat) -> Bool raise Errno

    Stat::is_character_device

    fn Stat::is_character_device(self : Stat) -> Bool

    Stat::is_directory

    fn Stat::is_directory(self : Stat) -> Bool

    Stat::is_fifo

    fn Stat::is_fifo(self : Stat) -> Bool

    Stat::is_file

    fn Stat::is_file(self : Stat) -> Bool

    Stat::is_pipe

    fn Stat::is_pipe(self : Stat) -> Bool

    Stat::is_regular

    fn Stat::is_regular(self : Stat) -> Bool

    Stat::is_socket

    fn Stat::is_socket(self : Stat) -> Bool raise Errno

    fn Stat::is_symlink(self : Stat) -> Bool

    Stat::mode

    fn Stat::mode(self : Stat) -> UInt64

    Stat::mtim_nsec

    fn Stat::mtim_nsec(self : Stat) -> Int64

    Stat::mtim_sec

    fn Stat::mtim_sec(self : Stat) -> Int64

    fn Stat::nlink(self : Stat) -> UInt64

    Stat::rdev

    fn Stat::rdev(self : Stat) -> UInt64

    Stat::size

    fn Stat::size(self : Stat) -> UInt64

    Stat::type_

    fn Stat::type_(self : Stat) -> DirentType

    Stat::uid

    fn Stat::uid(self : Stat) -> UInt64

    Status

    pub(all) enum Status {
    E2BIG
    EACCES
    EADDRINUSE
    EADDRNOTAVAIL
    EAFNOSUPPORT
    EAGAIN
    EAI_ADDRFAMILY
    EAI_AGAIN
    EAI_BADFLAGS
    EAI_BADHINTS
    EAI_CANCELED
    EAI_FAIL
    EAI_FAMILY
    EAI_MEMORY
    EAI_NODATA
    EAI_NONAME
    EAI_OVERFLOW
    EAI_PROTOCOL
    EAI_SERVICE
    EAI_SOCKTYPE
    EALREADY
    EBADF
    EBUSY
    ECANCELED
    ECHARSET
    ECONNABORTED
    ECONNREFUSED
    ECONNRESET
    EDESTADDRREQ
    EEXIST
    EFAULT
    EFBIG
    EHOSTUNREACH
    EINTR
    EINVAL
    EIO
    EISCONN
    EISDIR
    ELOOP
    EMFILE
    EMSGSIZE
    ENAMETOOLONG
    ENETDOWN
    ENETUNREACH
    ENFILE
    ENOBUFS
    ENODEV
    ENOENT
    ENOMEM
    ENONET
    ENOPROTOOPT
    ENOSPC
    ENOSYS
    ENOTCONN
    ENOTDIR
    ENOTEMPTY
    ENOTSOCK
    ENOTSUP
    EOVERFLOW
    EPERM
    EPIPE
    EPROTO
    EPROTONOSUPPORT
    EPROTOTYPE
    ERANGE
    EROFS
    ESHUTDOWN
    ESPIPE
    ESRCH
    ETIMEDOUT
    ETXTBSY
    EXDEV
    UNKNOWN
    EOF
    ENXIO
    EMLINK
    EHOSTDOWN
    EREMOTEIO
    ENOTTY
    EFTYPE
    EILSEQ
    ESOCKTNOSUPPORT
    ENODATA
    EUNATCH
    ENOEXEC
    }

    impl Eq for Status
    impl Hash for Status

    StdioContainer

    type StdioContainer

    StdioContainer::create_pipe

    fn[Stream : ToStream + ToHandle] StdioContainer::create_pipe(stream : Stream, readable~ : Bool = .., writable~ : Bool = .., non_block~ : Bool = ..) -> StdioContainer

    StdioContainer::ignore

    StdioContainer::inherit_file

    fn StdioContainer::inherit_file(file : File) -> StdioContainer

    StdioContainer::inherit_stream

    fn StdioContainer::inherit_stream(stream : Stream) -> StdioContainer

    Stream

    type Stream

    impl ToHandle for Stream
    impl ToStream for Stream

    Stream::is_readable

    fn Stream::is_readable(self : Stream) -> Bool

    Stream::is_writable

    fn Stream::is_writable(self : Stream) -> Bool

    Stream::read_start

    fn Stream::read_start(self : Stream, alloc_cb : (Handle, Int) ->
    View
    , read_cb : (Stream, Int,
    View
    ) -> Unit, error_cb : (Stream, Errno) -> Unit) -> Unit raise Errno

    Stream::read_stop

    fn Stream::read_stop(self : Stream) -> Unit raise Errno

    Stream::shutdown

    fn Stream::shutdown(self : Stream, shutdown_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Shutdown raise Errno

    Stream::to_handle

    fn Stream::to_handle(self : Stream) -> Handle

    Stream::write

    fn Stream::write(self : Stream, bufs : Array[
    View
    ], write_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Unit raise Errno

    Stream::write2

    fn Stream::write2(self : Stream, bufs : Array[
    View
    ], send_handle : Stream, write_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Unit raise Errno

    Tcp

    type Tcp

    impl ToHandle for Tcp
    impl ToStream for Tcp

    Tcp::bind

    fn[Sockaddr : ToSockaddr] Tcp::bind(self : Tcp, addr : Sockaddr, flags : TcpBindFlags) -> Unit raise Errno

    Tcp::connect

    fn[Sockaddr : ToSockaddr] Tcp::connect(self : Tcp, addr : Sockaddr, connect_cb : (Connect) -> Unit, error_cb : (Connect, Errno) -> Unit) -> Unit raise Errno

    Tcp::new

    fn Tcp::new(uv : Loop) -> Tcp raise Errno

    TcpBindFlags

    type TcpBindFlags

    TcpBindFlags::new

    fn TcpBindFlags::new(ipv6_only~ : Bool = .., reuse_port~ : Bool = ..) -> TcpBindFlags

    Thread

    type Thread

    impl Eq for Thread
    impl Share for Thread

    Thread::equal

    fn Thread::equal(self : Thread, other : Thread) -> Bool

    Thread::join

    fn Thread::join(self : Thread) -> Unit raise Errno

    Thread::new

    fn Thread::new(cb : () -> Unit) -> Thread raise Errno

    Thread::self

    fn Thread::self() -> Thread raise Errno

    Timer

    type Timer

    impl ToHandle for Timer

    Timer::get_due_in

    fn Timer::get_due_in(self : Timer) -> UInt64

    Timer::get_repeat

    fn Timer::get_repeat(self : Timer) -> UInt64

    Timer::new

    fn Timer::new(self : Loop) -> Timer raise Errno

    Timer::set_repeat

    fn Timer::set_repeat(self : Timer, repeat : UInt64) -> Unit

    Timer::start

    fn Timer::start(self : Timer, timeout~ : UInt64, repeat~ : UInt64, cb : (Timer) -> Unit) -> Unit raise Errno

    Timer::stop

    fn Timer::stop(self : Timer) -> Unit raise Errno

    Tty

    type Tty

    impl ToHandle for Tty
    impl ToStream for Tty

    Tty::get_winsize

    fn Tty::get_winsize(self : Tty) -> (Int, Int) raise Errno

    Tty::new

    fn Tty::new(self : Loop, file : File) -> Tty raise Errno

    Tty::reset_mode

    fn Tty::reset_mode() -> Unit raise Errno

    Tty::set_mode

    fn Tty::set_mode(self : Tty, mode : TtyMode) -> Unit raise Errno

    TtyMode

    type TtyMode

    TtyMode::io

    fn TtyMode::io() -> TtyMode

    TtyMode::normal

    fn TtyMode::normal() -> TtyMode

    TtyMode::raw

    fn TtyMode::raw() -> TtyMode

    TtyMode::raw_vt

    fn TtyMode::raw_vt() -> TtyMode

    Udp

    type Udp

    impl ToHandle for Udp

    Udp::bind

    fn[Sockaddr : ToSockaddr] Udp::bind(self : Udp, addr : Sockaddr, flags : UdpFlags) -> Unit raise Errno

    Udp::connect

    fn[Sockaddr : ToSockaddr] Udp::connect(self : Udp, addr : Sockaddr) -> Unit raise Errno

    Udp::new

    fn Udp::new(uv : Loop) -> Udp raise Errno

    Udp::recv_start

    fn Udp::recv_start(self : Udp, alloc_cb : (Handle, Int) ->
    View
    , read_cb : (Udp, Int,
    View
    , Sockaddr, UdpFlags) -> Unit, error_cb : (Udp, Errno) -> Unit) -> Unit raise Errno

    Udp::recv_stop

    fn Udp::recv_stop(self : Udp) -> Unit raise Errno

    Udp::send

    fn[Sockaddr : ToSockaddr] Udp::send(self : Udp, data : Array[
    View
    ], send_cb : (UdpSend) -> Unit, error_cb : (UdpSend, Errno) -> Unit, addr? : Sockaddr) -> Unit raise Errno

    UdpFlags

    type UdpFlags

    UdpFlags::new

    fn UdpFlags::new() -> UdpFlags

    UdpSend

    type UdpSend

    impl ToReq for UdpSend

    Uid

    type Uid

    Utsname

    type Utsname

    Utsname::machine

    fn Utsname::machine(self : Utsname) -> String

    Utsname::release

    fn Utsname::release(self : Utsname) -> String

    Utsname::sysname

    fn Utsname::sysname(self : Utsname) -> String

    Utsname::version

    fn Utsname::version(self : Utsname) -> String

    Work

    type Work

    impl Cancelable for Work
    impl ToReq for Work

    Write

    type Write

    impl ToReq for Write

    accept

    fn[Server : ToStream + ToHandle, Client : ToStream + ToHandle] accept(server : Server, client : Client) -> Unit raise Errno

    args

    fn args() -> Array[String]

    Returns a copy of command-line arguments passed to the program.

    The arguments are copied to prevent accidental/intentional modification to the original command-line arguments.

    Example:

    println(@uv.args())

    argv

    fn argv() -> Array[Bytes]

    chdir

    fn[Ntbs : ToNtbs] chdir(path : Ntbs) -> Unit raise Errno

    close

    fn[Handle : ToHandle] close(handle : Handle, cb : (Handle) -> Unit) -> Unit

    cpu_info

    fn cpu_info() -> Array[CpuInfo] raise Errno

    Returns current CPU information.

    Example:

    let cpu_infos = @uv.cpu_info()
    println(cpu_infos)

    cwd

    fn cwd() -> String raise Errno

    disable_stdio_inheritance

    fn disable_stdio_inheritance() -> Unit

    errno

    fn errno(errno : Status) -> Errno

    exepath

    fn exepath() -> String raise Errno

    hrtime

    fn hrtime() -> UInt64

    ip4_addr

    fn[Ntbs : ToNtbs] ip4_addr(ip : Ntbs, port : Int) -> SockaddrIn raise Errno

    Creates an IPv4 socket address structure from an IP address and port number.

    Parameters:

    • ip : The IPv4 address as a null-terminated byte string (e.g., "127.0.0.1").
    • port : The port number for the socket address.

    Returns a SockaddrIn structure representing the IPv4 socket address that can be used with TCP operations like binding or connecting.

    Example:

    let addr = @uv.ip4_addr("127.0.0.1", 8080)
    println(addr.ip_name())

    ip6_addr

    fn[Ntbs : ToNtbs] ip6_addr(ip : Ntbs, port : Int) -> SockaddrIn6 raise Errno

    is_closing

    fn[Handle : ToHandle] is_closing(handle : Handle) -> Bool

    is_readable

    fn[Stream : ToStream + ToHandle] is_readable(stream : Stream) -> Bool

    is_writable

    fn[Stream : ToStream + ToHandle] is_writable(stream : Stream) -> Bool

    listen

    fn[Stream : ToStream + ToHandle] listen(stream : Stream, backlog : Int, connection_cb : (Stream) -> Unit, error_cb : (Stream, Errno) -> Unit) -> Unit raise Errno

    os_environ

    fn os_environ() -> Environ raise Errno

    os_getenv

    fn[ToNtbs : ToNtbs] os_getenv(name : ToNtbs) -> String? raise Errno

    os_homedir

    fn os_homedir() -> String raise Errno

    os_setenv

    fn[Name : ToNtbs, Value : ToNtbs] os_setenv(name : Name, value : Value) -> Unit raise Errno

    os_tmpdir

    fn os_tmpdir() -> String raise Errno

    Retrieves the path to the system's temporary directory.

    Returns a String containing the path to the temporary directory where temporary files can be created.

    Throws an error of type Errno if the underlying system call fails or if there are insufficient resources to complete the operation.

    Example:

    println(@uv.os_tmpdir())

    os_uname

    fn os_uname() -> Utsname raise Errno

    Retrieves system information including the system name, release, version, and machine architecture.

    Returns a Utsname structure containing system identification information.

    Throws an error of type Errno if the underlying system call fails.

    Example:

    let info = @uv.os_uname()
    println(info.sysname())
    println(info.release())
    println(info.machine())

    os_unsetenv

    fn[Name : ToNtbs] os_unsetenv(name : Name) -> Unit raise Errno

    pipe

    fn pipe(read_flags : Int, write_flags : Int) -> (File, File) raise Errno

    read_start

    fn[Stream : ToStream + ToHandle] read_start(stream : Stream, alloc_cb : (Stream, Int) ->
    View
    , read_cb : (Stream, Int,
    View
    ) -> Unit, error_cb : (Stream, Errno) -> Unit) -> Unit raise Errno

    Starts reading from a stream with custom allocation and data handling callbacks.

    Parameters:

    • stream : The stream to read from.
    • alloc_cb : Callback function to allocate buffer space for incoming data. Takes the stream and suggested buffer size, returns a bytes view.
    • read_cb : Callback function to handle successfully read data. Takes the stream, number of bytes read, and the data as a bytes view.
    • error_cb : Callback function to handle read errors. Takes the stream and the error code.

    Throws an error of type Errno if the operation fails to start.

    read_stop

    fn[Stream : ToStream + ToHandle] read_stop(stream : Stream) -> Unit raise Errno

    shutdown

    fn[Stream : ToStream + ToHandle] shutdown(stream : Stream, shutdown_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Shutdown raise Errno

    sleep

    fn sleep(milliseconds : UInt) -> Unit

    stderr

    fn stderr() -> File

    stdin

    fn stdin() -> File

    stdout

    fn stdout() -> File

    write

    fn[Stream : ToStream + ToHandle] write(stream : Stream, bufs : Array[
    View
    ], write_cb : () -> Unit, error_cb : (Errno) -> Unit) -> Unit raise Errno