core/nbio

nbio

Types

56

Accept

Accept :: struct { // Socket to accept an incoming connection on. socket: TCP_Socket, // When this operation expires and should be timed out. expires: time.Time, // The connection that was accepted. client: TCP_Socket, // The connection's remote origin. client_endpoint: Endpoint, // An error, if it occurred. err: Accept_Error, // Implementation specifics, private. _impl: _Accept, }Source

Association_Error

Association_Error :: enum int { None = 0, // The given file/handle/socket was not opened in a mode that it can be made non-blocking afterwards. // // On Windows, this can happen when a file is not opened with the `FILE_FLAG_OVERLAPPED` flag. // If using `core:os`, that is set when you specify the `O_NONBLOCK` flag. // There is no way to add that after the fact. Not_Possible_To_Associate = 1, // The given handle is not a valid handle. Invalid_Handle = 2, // No network connection, or the network stack is not initialized. Network_Unreachable = 3, }Source

Bufs

Bufs :: struct { backing: [1][]u8, working: struct #raw_union { small: [1][]u8, big: [][]u8, }, }Source

In order to: 1. Not require the caller to allocate their buffers (op.send.bufs and op.recv.bufs can be stack allocated) 2. Have op.send.bufs and op.recv.bufs be valid and the same content in the callback as when called 3. Be able to facilitate the all option, which requires mutating the slices (advancing them) 4. Constraint single send/recv syscalls to MAX_RW bytes

We need to copy the input buffers twice, once for a stable copy returned to the user, and one for the working copy that we mutate with all set.

Close

Close :: struct { // The subject to close. subject: Closable, // An error, if it occurred. err: FS_Error, // Implementation specifics, private. _impl: _Close, }Source

Dial

Dial :: struct { // The endpoint to connect to. endpoint: Endpoint, // When this operation expires and should be timed out. expires: time.Time, // Errors that can be returned: `Create_Socket_Error`, or `Dial_Error`. err: Network_Error, // The socket to communicate with the connected server. socket: TCP_Socket, // Implementation specifics, private. _impl: _Dial, }Source

File_Flag

File_Flag :: enum int { // Open for reading. Read = 0, // Open for writing. Write = 1, // Append writes to the end of the file. Append = 2, // Create the file if it does not exist. Create = 3, // Fail if the file already exists (used with Create). Excl = 4, Sync = 5, // Truncate the file on open. Trunc = 6, }Source

File_Type

File_Type :: enum int { // File type could not be determined. Undetermined = 0, // Regular file. Regular = 1, // Directory. Directory = 2, // Symbolic link. Symlink = 3, // Pipe or socket. Pipe_Or_Socket = 4, // Character or block device. Device = 5, }Source

Open

Open :: struct { // Base directory the path is relative to. dir: Handle, // Path to the file. path: string, // File open mode flags. mode: File_Flags, // Permissions used if the file is created. perm: Permissions, // The opened file handle. handle: Handle, // An error, if it occurred. err: FS_Error, // Implementation specifics, private. _impl: _Open, }Source

Operation_Type

Operation_Type :: enum i32 { None = 0, Accept = 1, Close = 2, Dial = 3, Read = 4, Recv = 5, Send = 6, Write = 7, Timeout = 8, Poll = 9, Send_File = 10, Open = 11, Stat = 12, _Link_Timeout = 13, _Remove = 14, _Splice = 15, }Source

Permission_Flag

Permission_Flag :: enum u32 { Execute_Other = 0, Write_Other = 1, Read_Other = 2, Execute_Group = 3, Write_Group = 4, Read_Group = 5, Execute_User = 6, Write_User = 7, Read_User = 8, }Source

Poll

Poll :: struct { // Socket to poll. socket: Any_Socket, // Event to poll for. event: Poll_Event, // When this operation expires and should be timed out. expires: time.Time, // Result of the poll. result: Poll_Result, // Implementation specifics, private. _impl: _Poll, }Source

Poll_Event

Poll_Event :: enum int { // The subject is ready to be received from. Receive = 0, // The subject is ready to be sent to. Send = 1, }Source

Poll_Result

Poll_Result :: enum i32 { // The requested event is ready. Ready = 0, // The operation timed out before the event became ready. Timeout = 1, // The socket was invalid. Invalid_Argument = 2, // An unspecified error occurred. Error = 3, }Source

Read

Read :: struct { // Handle to read from. handle: Handle, // Buffer to read data into. buf: []u8, // Offset to read from. offset: int, // Whether to read until the buffer is full or an error occurs. all: bool, // When this operation expires and should be timed out. expires: time.Time, // Error, if it occurred. err: FS_Error, // Number of bytes read. read: int, // Implementation specifics, private. _impl: _Read, }Source

Recv

Recv :: struct { // The socket to receive from. socket: Any_Socket, // The buffers to receive data into. // The outer slice is copied internally, but the backing data must remain alive. // It is safe to access `bufs` during the callback. bufs: [][]u8, // If true, the operation waits until all buffers are filled (TCP only). all: bool, // When this operation expires and should be timed out. expires: time.Time, // The source endpoint data was received from (UDP only). source: Endpoint, // An error, if it occurred. // If `received == 0` and `err == nil`, the connection was closed by the peer. err: Recv_Error, // The number of bytes received. received: int, // Implementation specifics, private. _impl: _Recv, }Source

Send

Send :: struct { // The socket to send to. socket: Any_Socket, // The buffers to send. // The outer slice is copied internally, but the backing data must remain alive. // It is safe to access `bufs` during the callback. bufs: [][]u8, // The destination endpoint to send to (UDP only). endpoint: Endpoint, // If true, the operation ensures all data is sent before completing. all: bool, // When this operation expires and should be timed out. expires: time.Time, // An error, if it occurred. err: Send_Error, // The number of bytes sent. sent: int, // Implementation specifics, private. _impl: _Send, }Source

Send_File

Send_File :: struct { // The TCP socket to send the file over. socket: TCP_Socket, // The handle of the regular file to send. file: Handle, // When this operation expires and should be timed out. expires: time.Time, // The starting offset within the file. offset: int, // Number of bytes to send. If set to SEND_ENTIRE_FILE, the file size is retrieved // automatically and this field is updated to reflect the full size. nbytes: int, // If true, the callback is triggered periodically as data is sent. // The callback will continue to be called until `sent == nbytes` or an error occurs. progress_updates: bool, // Total number of bytes (so far if `progress_updates` is true). sent: int, // An error, if it occurred. Can be a filesystem or networking error. err: Send_File_Error, // Implementation specifics, private. _impl: _Send_File, }Source

Stat

Stat :: struct { // Handle to stat. handle: Handle, // The type of the file. type: File_Type, // Size of the file in bytes. size: i64, // An error, if it occurred. err: FS_Error, // Implementation specifics, private. _impl: _Stat, }Source

Timeout

Timeout :: struct { // Duration after which the timeout expires. duration: time.Duration, // Implementation specifics, private. _impl: _Timeout, }Source

Write

Write :: struct { // Handle to write to. handle: Handle, // Buffer containing data to write. buf: []u8, // Offset to write to. offset: int, // Whether to write until the buffer is fully written or an error occurs. all: bool, // When this operation expires and should be timed out. expires: time.Time, // Error, if it occurred. err: FS_Error, // Number of bytes written. written: int, // Implementation specifics, private. _impl: _Write, }Source

Constants

33

CWD

CWD :: _CWDSource

Sentinel handle representing the current/present working directory.

Variables

1

Procedures

155

accept

accept :: proc(socket: TCP_Socket, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Using the given socket, accepts the next incoming connection, calling the callback when that happens.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under accept_poly, accept_poly2, and accept_poly3.

  • socket: A bound and listening socket associated with the event loop
  • cb: The callback to be called when the operation finishes, Operation.accept will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

accept_poly

accept_poly :: proc(socket: TCP_Socket, p: T, cb: C, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Using the given socket, accepts the next incoming connection, calling the callback when that happens.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: A bound and listening socket associated with the event loop
  • p: User data, the callback will receive this as it's second argument
  • cb: The callback to be called when the operation finishes, Operation.accept will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

accept_poly2

accept_poly2 :: proc( socket: TCP_Socket, p: T, p2: T2, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Using the given socket, accepts the next incoming connection, calling the callback when that happens.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: A bound and listening socket associated with the event loop
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The callback to be called when the operation finishes, Operation.accept will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

accept_poly3

accept_poly3 :: proc( socket: TCP_Socket, p: T, p2: T2, p3: T3, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Using the given socket, accepts the next incoming connection, calling the callback when that happens.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: A bound and listening socket associated with the event loop
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The callback to be called when the operation finishes, Operation.accept will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

associate_handle

associate_handle :: proc(handle: uintptr, l: ^Event_Loop, loc = #caller_location) -> (Association_Error, Handle)Source

Associate the given OS handle, not opened through this package, with the event loop.

Consider using this package's open or open_sync directly instead.

The handle returned is for convenience, it is actually still the same handle as given. Thus you should not close the given handle.

On Windows, this can error when a file is not opened with the FILE_FLAG_OVERLAPPED flag. If using core:os, that is set when you specify the O_NONBLOCK flag. There is no way to add that after the fact.

close

close :: proc(subject: Closable, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Closes the given subject (file or socket).

Closing something that has IO in progress may or may not cancel it, and may or may not call the callback. For consistent behavior first call remove on in progress IO.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under close_poly, close_poly2, and close_poly3.

  • subject: The subject (socket or file) to close
  • cb: The optional callback to be called when the operation finishes, Operation.close will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

close_poly

close_poly :: proc(subject: Closable, p: T, cb: C, l: ^Event_Loop) -> (^Operation)Source

Closes the given subject (file or socket).

Closing something that has IO in progress may or may not cancel it, and may or may not call the callback. For consistent behavior first call remove on in progress IO.

This procedure uses polymorphism for type safe user data up to a certain size.

  • subject: The subject (socket or file) to close
  • p: User data, the callback will receive this as it's second argument
  • cb: The optional callback to be called when the operation finishes, Operation.close will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

close_poly2

close_poly2 :: proc(subject: Closable, p: T, p2: T2, cb: C, l: ^Event_Loop) -> (^Operation)Source

Closes the given subject (file or socket).

Closing something that has IO in progress may or may not cancel it, and may or may not call the callback. For consistent behavior first call remove on in progress IO.

This procedure uses polymorphism for type safe user data up to a certain size.

  • subject: The subject (socket or file) to close
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The optional callback to be called when the operation finishes, Operation.close will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

close_poly3

close_poly3 :: proc( subject: Closable, p: T, p2: T2, p3: T3, cb: C, l: ^Event_Loop, ) -> (^Operation)Source

Closes the given subject (file or socket).

Closing something that has IO in progress may or may not cancel it, and may or may not call the callback. For consistent behavior first call remove on in progress IO.

This procedure uses polymorphism for type safe user data up to a certain size.

  • subject: The subject (socket or file) to close
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The optional callback to be called when the operation finishes, Operation.close will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

create_socket

create_socket :: proc(family: Address_Family, protocol: Socket_Protocol, l: ^Event_Loop, loc = #caller_location) -> (socket: Any_Socket, err: Create_Socket_Error)Source

Creates a socket for use in nbio and relates it to the given event loop.

  • family: Should this be an IP4 or IP6 socket
  • protocol: The type of socket (TCP or UDP)
  • l: The event loop to associate it with, defaults to the current thread's loop
  • socket: The created socket, consider create_{udp|tcp}_socket for a typed socket instead of the union
  • err: A network error (Create_Socket_Error, or Set_Blocking_Error) which happened while opening

detach

detach :: proc(op: ^Operation)Source

Detach an operation from the package's lifetime management.

By default the operation's lifetime is managed by the package and freed after a callback is called. Calling this function detaches the operation from this lifetime. You are expected to call reattach to give the package back this operation.

dial

dial :: proc(endpoint: Endpoint, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Dials the given endpoint.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under dial_poly, dial_poly2, and dial_poly3.

  • endpoint: The endpoint to connect to
  • cb: The callback to be called when the operation finishes, Operation.dial will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

dial_poly

dial_poly :: proc(endpoint: Endpoint, p: T, cb: C, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Dials the given endpoint.

This procedure uses polymorphism for type safe user data up to a certain size.

  • endpoint: The endpoint to connect to
  • p: User data, the callback will receive this as it's second argument
  • cb: The callback to be called when the operation finishes, Operation.dial will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

dial_poly2

dial_poly2 :: proc( endpoint: Endpoint, p: T, p2: T2, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Dials the given endpoint.

This procedure uses polymorphism for type safe user data up to a certain size.

  • endpoint: The endpoint to connect to
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The callback to be called when the operation finishes, Operation.dial will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

dial_poly3

dial_poly3 :: proc( endpoint: Endpoint, p: T, p2: T2, p3: T3, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Dials the given endpoint.

This procedure uses polymorphism for type safe user data up to a certain size.

  • endpoint: The endpoint to connect to
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The callback to be called when the operation finishes, Operation.dial will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

exec

exec :: proc(op: ^Operation, trigger_wake_up: untyped boolean = true)Source

Execute an operation.

If the operation is attached to another thread's event loop, it is queued to be executed on that event loop, optionally waking that loop up (from a blocking tick) with trigger_wake_up.

listen_tcp

listen_tcp :: proc(endpoint: Endpoint, backlog: untyped integer = 1000, l: ^Event_Loop, loc = #caller_location) -> (socket: TCP_Socket, err: net.Network_Error)Source

Creates a socket, sets non blocking mode, relates it to the given IO, binds the socket to the given endpoint and starts listening.

  • endpoint: Where to bind the socket to
  • backlog: The maximum length to which the queue of pending connections may grow, before refusing connections
  • l: The event loop to associate the socket with, defaults to the current thread's loop

now

now :: proc() -> (time.Time)Source

Returns the current time (cached at most at the beginning of the current tick).

open

open :: proc( path: string, cb: Callback, mode: File_Flags, perm: Permissions, dir: Handle, l: ^Event_Loop, ) -> (^Operation)Source

Opens a file and associates it with the event loop.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under open_poly, open_poly2, and open_poly3.

  • path: Path to the file, if not absolute: relative from dir
  • cb: The callback to be called when the operation finishes, Operation.open will contain results
  • mode: File open mode flags, defaults to read-only
  • perm: Permissions to use when creating a file, defaults to read+write for everybody
  • dir: Directory that path is relative from (if it is relative), defaults to the current working directory
  • l: Event loop to associate the operation with, defaults to the current thread's loop

open_poly

open_poly :: proc( path: string, p: T, cb: C, mode: File_Flags, perm: Permissions, dir: Handle, l: ^Event_Loop, ) -> (^Operation)Source

Opens a file and associates it with the event loop.

This procedure uses polymorphism for type safe user data up to a certain size.

  • path: Path to the file, if not absolute: relative from dir
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes, Operation.open will contain results
  • mode: File open mode flags, defaults to read-only
  • perm: Permissions to use when creating a file, defaults to read+write for everybody
  • dir: Directory that path is relative from (if it is relative), defaults to the current working directory
  • l: Event loop to associate the operation with, defaults to the current thread's loop

open_poly2

open_poly2 :: proc( path: string, p: T, p2: T2, cb: C, mode: File_Flags, perm: Permissions, dir: Handle, l: ^Event_Loop, ) -> (^Operation)Source

Opens a file and associates it with the event loop.

This procedure uses polymorphism for type safe user data up to a certain size.

  • path: Path to the file, if not absolute: relative from dir
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes, Operation.open will contain results
  • mode: File open mode flags, defaults to read-only
  • perm: Permissions to use when creating a file, defaults to read+write for everybody
  • dir: Directory that path is relative from (if it is relative), defaults to the current working directory
  • l: Event loop to associate the operation with, defaults to the current thread's loop

open_poly3

open_poly3 :: proc( path: string, p: T, p2: T2, p3: T3, cb: C, mode: File_Flags, perm: Permissions, dir: Handle, l: ^Event_Loop, ) -> (^Operation)Source

Asynchronously opens a file and associates it with the event loop.

This procedure uses polymorphism for type safe user data up to a certain size.

  • path: Path to the file, if not absolute: relative from dir
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes, Operation.open will contain results
  • mode: File open mode flags, defaults to read-only
  • perm: Permissions to use when creating a file, defaults to read+write for everybody
  • dir: Directory that path is relative from (if it is relative), defaults to the current working directory
  • l: Event loop to associate the operation with, defaults to the current thread's loop

open_sync

open_sync :: proc( path: string, dir: Handle, mode: File_Flags, perm: _ = Permissions_Default_File, l: ^Event_Loop, loc: _ = #caller_location, ) -> (handle: Handle, err: FS_Error)Source

Opens a file and associates it with the event loop.

  • path: path to the file, if not absolute: relative from dir
  • dir: directory that path is relative from (if it is relative), defaults to the current working directory
  • mode: open mode, defaults to read-only
  • perm: permissions to use when creating a file, defaults to read+write for everybody
  • l: event loop to associate the file with, defaults to the current thread's
  • handle: The file handle
  • err: An error if it occurred

poll

poll :: proc(socket: Any_Socket, event: Poll_Event, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Poll a socket for readiness.

NOTE: this is provided to help with "legacy" APIs that require polling behavior. If you can avoid it and use the other procs in this package, do so.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under poll_poly, poll_poly2, and poll_poly3.

  • socket: Socket to poll that is associated with the event loop
  • event: Event to poll for
  • cb: The callback to be called when the operation finishes, Operation.poll will contain results
  • timeout: Optional timeout for the operation, the callback will receive a .Timeout result after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

poll_poly

poll_poly :: proc( socket: Any_Socket, event: Poll_Event, p: T, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Poll a socket for readiness.

NOTE: this is provided to help with "legacy" APIs that require polling behavior. If you can avoid it and use the other procs in this package, do so.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: Socket to poll that is associated with the event loop
  • event: Event to poll for
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes, Operation.poll will contain results
  • timeout: Optional timeout for the operation, the callback will receive a .Timeout result after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

poll_poly2

poll_poly2 :: proc( socket: Any_Socket, event: Poll_Event, p: T, p2: T2, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Poll a socket for readiness.

NOTE: this is provided to help with "legacy" APIs that require polling behavior. If you can avoid it and use the other procs in this package, do so.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: Socket to poll that is associated with the event loop
  • event: Event to poll for
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes, Operation.poll will contain results
  • timeout: Optional timeout for the operation, the callback will receive a .Timeout result after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

poll_poly3

poll_poly3 :: proc( socket: Any_Socket, event: Poll_Event, p: T, p2: T2, p3: T3, cb: C, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Poll a socket for readiness.

NOTE: this is provided to help with "legacy" APIs that require polling behavior. If you can avoid it and use the other procs in this package, do so.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: Socket to poll that is associated with the event loop
  • event: Event to poll for
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes, Operation.poll will contain results
  • timeout: Optional timeout for the operation, the callback will receive a .Timeout result after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_accept

prep_accept :: proc(socket: TCP_Socket, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps an operation to do an accept without executing it.

Executing can then be done with the exec procedure.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • socket: A bound and listening socket associated with the event loop
  • cb: The callback to be called when the operation finishes, Operation.accept will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_close

prep_close :: proc(subject: Closable, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps an operation to do a close without executing it.

Executing can then be done with the exec procedure.

Closing something that has IO in progress may or may not cancel it, and may or may not call the callback. For consistent behavior first call remove on in progress IO.

Any user data can be set on the returned operation's user_data field.

  • subject: The subject (socket or file) to close
  • cb: The optional callback to be called when the operation finishes, Operation.close will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_dial

prep_dial :: proc(endpoint: Endpoint, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps an operation to do a dial operation without executing it.

Executing can then be done with the exec procedure.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • endpoint: The endpoint to connect to
  • cb: The callback to be called when the operation finishes, Operation.dial will contain results
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_open

prep_open :: proc( path: string, cb: Callback, mode: File_Flags, perm: Permissions, dir: Handle, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps an operation to open a file without executing it.

Executing can then be done with the exec procedure.

Any user data can be set on the returned operation's user_data field.

  • path: Path to the file, if not absolute: relative from dir
  • cb: The callback to be called when the operation finishes, Operation.open will contain results
  • mode: File open mode flags, defaults to read-only
  • perm: Permissions to use when creating a file, defaults to read+write for everybody
  • dir: Directory that path is relative from (if it is relative), defaults to the current working directory
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_poll

prep_poll :: proc(socket: Any_Socket, event: Poll_Event, cb: Callback, timeout: time.Duration, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps an operation to poll a socket without executing it.

Executing can then be done with the exec procedure.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • socket: Socket to poll that is associated with the event loop
  • event: Event to poll for
  • cb: The callback to be called when the operation finishes, Operation.poll will contain results
  • timeout: Optional timeout for the operation, the callback will receive a .Timeout result after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_read

prep_read :: proc( handle: Handle, offset: int, buf: []u8, cb: Callback, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps a positional read operation without executing it.

This is a pread-style operation: the read starts at the given offset and does not modify the handle's current file position.

Executing can then be done with the exec procedure.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • handle: Handle to read from
  • offset: Offset to read from
  • buf: Buffer to read data into (must not be empty)
  • cb: The callback to be called when the operation finishes, Operation.read will contain results
  • all: Whether to read until the buffer is full or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_recv

prep_recv :: proc( socket: Any_Socket, bufs: [][]u8, cb: Callback, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps an operation to do a receive without executing it.

Executing can then be done with the exec procedure.

To avoid ambiguity between a closed connection and a 0-byte read, the provided buffers must have a total capacity greater than 0.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • socket: The socket to receive from
  • bufs: Buffers to fill with received data
  • cb: The callback to be called when the operation finishes, Operation.recv will contain results
  • all: If true, waits until all buffers are full before completing (TCP only, ignored for UDP)
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_send

prep_send :: proc( socket: Any_Socket, bufs: [][]u8, cb: Callback, endpoint: Endpoint, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps an operation to do a send without executing it.

Executing can then be done with the exec procedure.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • socket: The socket to send to
  • bufs: Buffers containing the data to send
  • cb: The callback to be called when the operation finishes, Operation.send will contain results
  • endpoint: The destination endpoint (UDP only, ignored for TCP)
  • all: If true, the operation ensures all data is sent before completing
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_sendfile

prep_sendfile :: proc( socket: TCP_Socket, file: Handle, cb: Callback, offset: int, nbytes: int, progress_updates: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps an operation to send a file over a socket without executing it.

Executing can then be done with the exec procedure.

This uses high-performance zero-copy system calls where available. Note: This is emulated on NetBSD and OpenBSD (stat -> mmap -> send) as they lack a native sendfile implementation.

Any user data can be set on the returned operation's user_data field.

  • socket: The destination TCP socket
  • file: The source file handle
  • cb: The callback to be called when data is sent (if progress_updates is true) or the operation completes
  • offset: Byte offset to start reading from the file
  • nbytes: Total bytes to send (use SEND_ENTIRE_FILE for the whole file)
  • progress_updates: If true, the callback fires multiple times to report progress, sent == nbytes means te operation completed
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_stat

prep_stat :: proc(handle: Handle, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps an operation to stat a handle without executing it.

Executing can then be done with the exec procedure.

Any user data can be set on the returned operation's user_data field.

  • handle: Handle to retrieve stat
  • cb: The callback to be called when the operation finishes, Operation.stat will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_timeout

prep_timeout :: proc(duration: time.Duration, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Retrieves and preps a timeout operation without executing it.

Executing can then be done with the exec procedure.

Any user data can be set on the returned operation's user_data field.

  • duration: Duration to wait before the operation completes
  • cb: The callback to be called when the operation finishes
  • l: Event loop to associate the operation with, defaults to the current thread's loop

prep_write

prep_write :: proc( handle: Handle, offset: int, buf: []u8, cb: Callback, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Retrieves and preps a positional write operation without executing it.

This is a pwrite-style operation: the write starts at the given offset and does not modify the handle's current file position.

Executing can then be done with the exec procedure.

The timeout is calculated from the time when this procedure was called, not from when it's executed.

Any user data can be set on the returned operation's user_data field.

  • handle: Handle to write to
  • offset: Offset to write to
  • buf: Buffer containing data to write (must not be empty)
  • cb: The callback to be called when the operation finishes, Operation.write will contain results
  • all: Whether to write until the entire buffer is written or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

read

read :: proc( handle: Handle, offset: int, buf: []u8, cb: Callback, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Reads data from a handle at a specific offset.

This is a pread-style operation: the read starts at the given offset and does not modify the handle's current file position.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under read_poly, read_poly2, and read_poly3.

  • handle: Handle to read from
  • offset: Offset to read from
  • buf: Buffer to read data into (must not be empty)
  • cb: The callback to be called when the operation finishes, Operation.read will contain results
  • all: Whether to read until the buffer is full or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

read_entire_file

read_entire_file :: proc( path: string, user_data: rawptr, cb: Read_Entire_File_Callback, allocator: mem.Allocator = context.allocator, dir: _ = CWD, l: ^Event_Loop, loc: _ = #caller_location, )Source

Combines multiple operations (open, stat, read, close) into one that reads an entire regular file.

The error contains the operation that the error happened on.

  • path: path to the file, if not absolute: relative from dir
  • user_data: a pointer passed through into the callback
  • cb: the callback to call once completed, called with the user data, file data, and an optional error
  • allocator: the allocator to allocate the file's contents onto
  • dir: directory that path is relative from (if it is relative), defaults to the current working directory
  • l: event loop to execute the operation on

read_poly

read_poly :: proc( handle: Handle, offset: int, buf: []u8, p: T, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Reads data from a handle at a specific offset.

This is a pread-style operation: the read starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to read from
  • offset: Offset to read from
  • buf: Buffer to read data into (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes, Operation.read will contain results
  • all: Whether to read until the buffer is full or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

read_poly2

read_poly2 :: proc( handle: Handle, offset: int, buf: []u8, p: T, p2: T2, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Reads data from a handle at a specific offset.

This is a pread-style operation: the read starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to read from
  • offset: Offset to read from
  • buf: Buffer to read data into (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes, Operation.read will contain results
  • all: Whether to read until the buffer is full or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

read_poly3

read_poly3 :: proc( handle: Handle, offset: int, buf: []u8, p: T, p2: T2, p3: T3, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Reads data from a handle at a specific offset.

This is a pread-style operation: the read starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to read from
  • offset: Offset to read from
  • buf: Buffer to read data into (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes, Operation.read will contain results
  • all: Whether to read until the buffer is full or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

recv

recv :: proc( socket: Any_Socket, bufs: [][]u8, cb: Callback, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Receives data from the socket.

If the operation completes with 0 bytes received and no error, it indicates the connection was closed by the peer.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under recv_poly, recv_poly2, and recv_poly3.

  • socket: The socket to receive from
  • bufs: Buffers to fill with received data
  • cb: The callback to be called when the operation finishes, Operation.recv will contain results
  • all: If true, waits until all buffers are full before completing (TCP only, ignored for UDP)
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

recv_poly

recv_poly :: proc( socket: Any_Socket, bufs: [][]u8, p: T, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Receives data from the socket.

If the operation completes with 0 bytes received and no error, it indicates the connection was closed by the peer.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to receive from
  • bufs: Buffers to fill with received data
  • p: User data, the callback will receive this as it's second argument
  • cb: The callback to be called when the operation finishes, Operation.recv will contain results
  • all: If true, waits until all buffers are full before completing (TCP only, ignored for UDP)
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

recv_poly2

recv_poly2 :: proc( socket: Any_Socket, bufs: [][]u8, p: T, p2: T2, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Receives data from the socket.

If the operation completes with 0 bytes received and no error, it indicates the connection was closed by the peer.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to receive from
  • bufs: Buffers to fill with received data
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The callback to be called when the operation finishes, Operation.recv will contain results
  • all: If true, waits until all buffers are full before completing (TCP only, ignored for UDP)
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

recv_poly3

recv_poly3 :: proc( socket: Any_Socket, bufs: [][]u8, p: T, p2: T2, p3: T3, cb: C, all: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Receives data from the socket.

If the operation completes with 0 bytes received and no error, it indicates the connection was closed by the peer.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to receive from
  • bufs: Buffers to fill with received data
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The callback to be called when the operation finishes, Operation.recv will contain results
  • all: If true, waits until all buffers are full before completing (TCP only, ignored for UDP)
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

remove

remove :: proc(target: ^Operation)Source

Remove the given operation from the event loop. The callback of it won't be called and resources are freed.

Calling remove:

  • Cancels the operation if it has not yet completed
  • Prevents the callback from being called

Cancellation via remove is final and silent:

  • The callback will never be invoked
  • No error is delivered
  • The operation must be considered dead after removal

WARN: the operation could have already been (partially or completely) completed.

  A send with `all` set to true could have sent a portion already.
	  But also, a send that could be completed without blocking could have been completed.
	  You just won't get a callback.

WARN: once an operation's callback is called it can not be removed anymore (use after free).

WARN: needs to be called from the thread of the event loop the target belongs to.

Common use would be to cancel a timeout, remove a polling, or remove an `accept` before calling `close` on it's socket.

send

send :: proc( socket: Any_Socket, bufs: [][]u8, cb: Callback, endpoint: Endpoint, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends data to the socket.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under send_poly, send_poly2, and send_poly3.

  • socket: The socket to send to
  • bufs: Buffers containing the data to send
  • cb: The callback to be called when the operation finishes, Operation.send will contain results
  • endpoint: The destination endpoint (UDP only, ignored for TCP)
  • all: If true, the operation ensures all data is sent before completing
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

send_poly

send_poly :: proc( socket: Any_Socket, bufs: [][]u8, p: T, cb: C, endpoint: Endpoint, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends data to the socket.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to send to
  • bufs: Buffers containing the data to send
  • p: User data, the callback will receive this as it's second argument
  • cb: The callback to be called when the operation finishes, Operation.send will contain results
  • endpoint: The destination endpoint (UDP only, ignored for TCP)
  • all: If true, the operation ensures all data is sent before completing
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

send_poly2

send_poly2 :: proc( socket: Any_Socket, bufs: [][]u8, p: T, p2: T2, cb: C, endpoint: Endpoint, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends data to the socket.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to send to
  • bufs: Buffers containing the data to send
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The callback to be called when the operation finishes, Operation.send will contain results
  • endpoint: The destination endpoint (UDP only, ignored for TCP)
  • all: If true, the operation ensures all data is sent before completing
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

send_poly3

send_poly3 :: proc( socket: Any_Socket, bufs: [][]u8, p: T, p2: T2, p3: T3, cb: C, endpoint: Endpoint, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends data to the socket.

The bufs slice itself is copied into the operation, so it can be temporary (e.g. on the stack), but the underlying memory of the buffers must remain valid until the callback is fired.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The socket to send to
  • bufs: Buffers containing the data to send
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The callback to be called when the operation finishes, Operation.send will contain results
  • endpoint: The destination endpoint (UDP only, ignored for TCP)
  • all: If true, the operation ensures all data is sent before completing
  • timeout: Optional timeout for the operation, the callback will get a .Timeout error after that duration
  • l: Event loop to associate the operation with, defaults to the current thread's loop

sendfile

sendfile :: proc( socket: TCP_Socket, file: Handle, cb: Callback, offset: int, nbytes: int, progress_updates: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends a file over a TCP socket.

This uses high-performance zero-copy system calls where available. Note: This is emulated on NetBSD and OpenBSD (stat -> mmap -> send) as they lack a native sendfile implementation.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under sendfile_poly, sendfile_poly2, and sendfile_poly3.

  • socket: The destination TCP socket
  • file: The source file handle
  • cb: The callback to be called when data is sent (if progress_updates is true) or the operation completes
  • offset: Byte offset to start reading from the file
  • nbytes: Total bytes to send (use SEND_ENTIRE_FILE for the whole file)
  • progress_updates: If true, the callback fires multiple times to report progress, sent == nbytes means te operation completed
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

sendfile_exec

sendfile_exec :: proc(op: ^Operation, splice: untyped boolean = true)Source

sendfile is implemented with 2 splices over a pipe.

Splice A: from file to pipe Splice B: from pipe to socket (optionally linked to a timeout)

The splices are hard-linked which means A completes before B. B could get an EWOULDBLOCK, which is when the remote end has not read enough of the socket data yet. In that case we enqueue a poll on the socket and continue when that completes. A shouldn't get EWOULDBLOCK, but as a cautionary measure we handle it.

The timeout is either linked to the splice B op, or the poll op, either of these is also always in progress in the kernel.

sendfile_poly

sendfile_poly :: proc( socket: TCP_Socket, file: Handle, p: T, cb: C, offset: int, nbytes: int, progress_updates: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends a file over a TCP socket.

This uses high-performance zero-copy system calls where available. Note: This is emulated on NetBSD and OpenBSD (stat -> mmap -> send) as they lack a native sendfile implementation.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The destination TCP socket
  • file: The source file handle
  • p: User data, the callback will receive this as it's second argument
  • cb: The callback to be called when data is sent (if progress_updates is true) or the operation completes
  • offset: Byte offset to start reading from the file
  • nbytes: Total bytes to send (use SEND_ENTIRE_FILE for the whole file)
  • progress_updates: If true, the callback fires multiple times to report progress, sent == nbytes means te operation completed
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

sendfile_poly2

sendfile_poly2 :: proc( socket: TCP_Socket, file: Handle, p: T, p2: T2, cb: C, offset: int, nbytes: int, progress_updates: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends a file over a TCP socket.

This uses high-performance zero-copy system calls where available. Note: This is emulated on NetBSD and OpenBSD (stat -> mmap -> send) as they lack a native sendfile implementation.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The destination TCP socket
  • file: The source file handle
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • cb: The callback to be called when data is sent (if progress_updates is true) or the operation completes
  • offset: Byte offset to start reading from the file
  • nbytes: Total bytes to send (use SEND_ENTIRE_FILE for the whole file)
  • progress_updates: If true, the callback fires multiple times to report progress, sent == nbytes means te operation completed
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

sendfile_poly3

sendfile_poly3 :: proc( socket: TCP_Socket, file: Handle, p: T, p2: T2, p3: T3, cb: C, offset: int, nbytes: int, progress_updates: untyped boolean = false, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Sends a file over a TCP socket.

This uses high-performance zero-copy system calls where available. Note: This is emulated on NetBSD and OpenBSD (stat -> mmap -> send) as they lack a native sendfile implementation.

This procedure uses polymorphism for type safe user data up to a certain size.

  • socket: The destination TCP socket
  • file: The source file handle
  • p: User data, the callback will receive this as it's second argument
  • p2: User data, the callback will receive this as it's third argument
  • p3: User data, the callback will receive this as it's fourth argument
  • cb: The callback to be called when data is sent (if progress_updates is true) or the operation completes
  • offset: Byte offset to start reading from the file
  • nbytes: Total bytes to send (use SEND_ENTIRE_FILE for the whole file)
  • progress_updates: If true, the callback fires multiple times to report progress, sent == nbytes means te operation completed
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

stat

stat :: proc(handle: Handle, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Stats a handle.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under stat_poly, stat_poly2, and stat_poly3.

  • handle: Handle to retrieve status information for
  • cb: The callback to be called when the operation finishes, Operation.stat will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

stat_poly

stat_poly :: proc(handle: Handle, p: T, cb: C, l: ^Event_Loop) -> (^Operation)Source

Stats a handle.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to retrieve status information for
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes, Operation.stat will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

stat_poly2

stat_poly2 :: proc(handle: Handle, p: T, p2: T2, cb: C, l: ^Event_Loop) -> (^Operation)Source

Stats a handle.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to retrieve status information for
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes, Operation.stat will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

stat_poly3

stat_poly3 :: proc( handle: Handle, p: T, p2: T2, p3: T3, cb: C, l: ^Event_Loop, ) -> (^Operation)Source

Stats a handle.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to retrieve status information for
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes, Operation.stat will contain results
  • l: Event loop to associate the operation with, defaults to the current thread's loop

tick

tick :: proc(timeout: time.Duration) -> (General_Error)Source

Each time you call this the implementation checks its state and calls any callbacks which are ready. You would typically call this in a loop.

Blocks for up-to timeout waiting for events if there is nothing to do.

timeout

timeout :: proc(duration: time.Duration, cb: Callback, l: ^Event_Loop) -> (^Operation)Source

Schedules a timeout that completes after the given duration.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under timeout_poly, timeout_poly2, and timeout_poly3.

  • duration: Duration to wait before the operation completes
  • cb: The callback to be called when the operation finishes
  • l: Event loop to associate the operation with, defaults to the current thread's loop

timeout_poly

timeout_poly :: proc(dur: time.Duration, p: T, cb: C, l: ^Event_Loop) -> (^Operation)Source

Schedules a timeout that completes after the given duration.

This procedure uses polymorphism for type safe user data up to a certain size.

  • dur: Duration to wait before the operation completes
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes
  • l: Event loop to associate the operation with, defaults to the current thread's loop

timeout_poly2

timeout_poly2 :: proc(dur: time.Duration, p: T, p2: T2, cb: C, l: ^Event_Loop) -> (^Operation)Source

Schedules a timeout that completes after the given duration.

This procedure uses polymorphism for type safe user data up to a certain size.

  • dur: Duration to wait before the operation completes
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes
  • l: Event loop to associate the operation with, defaults to the current thread's loop

timeout_poly3

timeout_poly3 :: proc( dur: time.Duration, p: T, p2: T2, p3: T3, cb: C, l: ^Event_Loop, ) -> (^Operation)Source

Schedules a timeout that completes after the given duration.

This procedure uses polymorphism for type safe user data up to a certain size.

  • dur: Duration to wait before the operation completes
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes
  • l: Event loop to associate the operation with, defaults to the current thread's loop

wake_up

wake_up :: proc(l: ^Event_Loop)Source

Wake up an event loop on another thread which may be blocking for completed operations.

Commonly used with exec from a worker thread to have the event loop pick up that work. Note that by default exec already calls this procedure.

write

write :: proc( handle: Handle, offset: int, buf: []u8, cb: Callback, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Writes data to a handle at a specific offset.

This is a pwrite-style operation: the write starts at the given offset and does not modify the handle's current file position.

Any user data can be set on the returned operation's user_data field. Polymorphic variants for type safe user data are available under write_poly, write_poly2, and write_poly3.

  • handle: Handle to write to
  • offset: Offset to write to
  • buf: Buffer containing data to write (must not be empty)
  • cb: The callback to be called when the operation finishes, Operation.write will contain results
  • all: Whether to write until the entire buffer is written or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

write_poly

write_poly :: proc( handle: Handle, offset: int, buf: []u8, p: T, cb: C, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Writes data to a handle at a specific offset.

This is a pwrite-style operation: the write starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to write to
  • offset: Offset to write to
  • buf: Buffer containing data to write (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • cb: The callback to be called when the operation finishes, Operation.write will contain results
  • all: Whether to write until the entire buffer is written or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

write_poly2

write_poly2 :: proc( handle: Handle, offset: int, buf: []u8, p: T, p2: T2, cb: C, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Writes data to a handle at a specific offset.

This is a pwrite-style operation: the write starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to write to
  • offset: Offset to write to
  • buf: Buffer containing data to write (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • cb: The callback to be called when the operation finishes, Operation.write will contain results
  • all: Whether to write until the entire buffer is written or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

write_poly3

write_poly3 :: proc( handle: Handle, offset: int, buf: []u8, p: T, p2: T2, p3: T3, cb: C, all: untyped boolean = true, timeout: time.Duration, l: ^Event_Loop, ) -> (^Operation)Source

Writes data to a handle at a specific offset.

This is a pwrite-style operation: the write starts at the given offset and does not modify the handle's current file position.

This procedure uses polymorphism for type safe user data up to a certain size.

  • handle: Handle to write to
  • offset: Offset to write to
  • buf: Buffer containing data to write (must not be empty)
  • p: User data, the callback will receive this as its second argument
  • p2: User data, the callback will receive this as its third argument
  • p3: User data, the callback will receive this as its fourth argument
  • cb: The callback to be called when the operation finishes, Operation.write will contain results
  • all: Whether to write until the entire buffer is written or an error occurs
  • timeout: Optional timeout for the operation
  • l: Event loop to associate the operation with, defaults to the current thread's loop

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.