EMILUA(3em)

πŸ“¦ version 0.12.1, in nixos 26.05, nixpkgs unstable

πŸ’œ NAME πŸ’œ

Emilua β€” the Lua execution engine, bestie. That's it, that's the whole vibe. It's giving runtime, it's giving engine, and yes we're about to get into the Unix datagram socket of it all.


✨ SYNOPSIS ✨

okay so here's the little taste-test, no cap:

local sock = unix.datagram.socket.new()
sock.open()
sock.bind(filesystem.path.new('/tmp/9Lq7BNBnBycd6nxy.socket'))

local buf = byte_span.new(1024)
local nread = sock:receive(buf)
print(buf:first(nread))

like… look at her go πŸ¦‹ she's binding, she's receiving, she's printing. main character energy fr fr.


🫢 FUNCTIONS 🫢

new() β†’ unix.datagram.socket

Two whole flavors, pick ur fighter:

  • new() β€” (1) the default constructor, the classic, the blueprint.
  • new(fd: file_descriptor) β€” (2) takes a file descriptor and converts it into an unix.datagram.socket object. glow-up in one call πŸ’…

pair() β†’ unix.datagram.socket, unix.datagram.socket

Creates a pair of connected sockets. two besties, already connected, iconic 🫢🫢

open(self)

Opens the socket. she's awake. ✨

bind(self, pathname: filesystem.path)

Binds the socket to the given local endpoint. like putting a name tag on her πŸŽ€

connect(self, pathname: filesystem.path)

Sets the default destination address so datagrams can be sent using send() without specifying a destination address. she now knows where she's going, lowkey efficient πŸ‘‘

disconnect(self)

Dissolves the socket's association by resetting the socket's peer address β€” i.e. connect(3) will be called with an AF_UNSPEC address. it's giving breakup arc 😭 but make it syscall.

close(self)

Closes the socket. bye bestie πŸ¦‹

Forward the call to the https://www.boost.org/doc/libs/1_70_0/doc/html/boost_asio/reference/basic_datagram_socket/close/overload2.html function with same name in Boost.Asio :

Any asynchronous send, receive or connect operations will be cancelled immediately, and will complete with the boost::asio::error::operation_aborted error.

shutdown(self, what: string)

Disables sends or receives on the socket. what can be one of the following:

  • "receive" β€” shut down the receive side of the socket.
  • "send" β€” shut down the send side of the socket.
  • "both" β€” shut down both send and receive on the socket.

pick ur vibe, choose wisely πŸ™ˆ

cancel(self)

Cancel all asynchronous operations associated with the acceptor πŸ”₯

Forward the call to the https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/reference/basic_datagram_socket/cancel/overload2.html function with same name in Boost.Asio :

This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error.

assign(self, fd: file_descriptor)

Assigns an existing native socket to self. adoption era 🫢

release(self) β†’ file_descriptor

Releases ownership of the native descriptor implementation. straight-up handing over the keys πŸ’€

Forward the call to the https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/reference/basic_datagram_socket/release/overload2.html function with same name in Boost.Asio :

This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error. Ownership of the native socket is then transferred to the caller.

receive(self, buffer: byte_span[, flags: string[]]) β†’ integer

Receives a datagram and blocks the current fiber until it completes or errs. Returns the number of bytes read. patient queen behavior 🌸

receive_from(self, buffer: byte_span[, flags: string[]]) β†’ integer, filesystem.path

Receives a datagram and blocks the current fiber until it completes or errs. Returns the number of bytes read plus the pathname of the remote sender of the datagram. now u know who sent it πŸ‘€

send(self, buffer: byte_span[, flags: string[]]) β†’ integer

Sends data on the datagram socket and blocks the current fiber until it completes or errs. Returns the number of bytes written.

Note: the send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket. don't come for me, that's just the rules 🫢

send_to(self, buffer: byte_span, pathname: filesystem.path[, flags: string[]]) β†’ integer

Sends a datagram to the specified remote endpoint and blocks the current fiber until it completes or errs. Returns the number of bytes written. she goes where u point her πŸ’…

receive_with_fds(self, buffer: byte_span, maxfds: integer) β†’ integer, file_descriptor[]

Receives a datagram and blocks the current fiber until it completes or errs. Returns the number of bytes read plus the table containing the fds read. file descriptors AND data?? multi-talented πŸ”₯

receive_from_with_fds(self, buffer: byte_span, maxfds: integer) β†’ integer, filesystem.path, file_descriptor[]

Receives a datagram and blocks the current fiber until it completes or errs. Returns the number of bytes read plus the pathname of the remote sender of the datagram plus the table containing the fds read. three-for-one, ate and left no crumbs πŸ‘‘

send_with_fds(self, buffer: byte_span, fds: file_descriptor[]) β†’ integer

Sends data on the datagram socket and blocks the current fiber until it completes or errs. Returns the number of bytes written.

Note: the send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket. yes it's the same note again, it's important, periodt πŸ’€

send_to_with_fds(self, buffer: byte_span, pathname: filesystem.path, fds: file_descriptor[]) β†’ integer

Sends a datagram to the specified remote endpoint and blocks the current fiber until it completes or errs. Returns the number of bytes written. fds traveling first class ✈️

set_option(self, opt: string, val)

Sets an option on the socket. currently available options are:

get_option(self, opt: string) β†’ value

Gets an option from the socket. currently available options are:

(yes, same three, but this one reads instead of writes. iykyk 🌈)

io_control(self, command: string[, ...])

Performs an IO control command on the socket. currently available commands are:

  • "bytes_readable" β€” expects no arguments. gets the amount of data that can be read without blocking. implements the FIONREAD IO control command. peek before u leap, bestie πŸ‘€βœ¨

πŸŽ€ FUNCTION FLAGS πŸŽ€

Peek at incoming data without removing it from the input queue.

like looking at ur notifications without opening them, honestly iconic πŸ“


πŸ¦‹ PROPERTIES πŸ¦‹

  • is_open: boolean β€” whether the socket is open. open or closed, no in-between πŸ’…
  • local_path: filesystem.path β€” the local address endpoint of the socket. where she lives 🏠
  • remote_path: filesystem.path β€” the remote address endpoint of the socket. where her people are 🌈

and that's the whole page, bestie πŸ’– this one shipped as Emilua 0.12.1-nixpkgs1, dated 1980-01-01 β€” yes, the date is a whole aesthetic, don't question it πŸ™ˆ go forth and send ur datagrams, mwah 🫢✨

πŸ“¦ where this page comes from