EMILUA(3em)
π 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 anunix.datagram.socketobject. 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:
"debug"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/debug.htmlBoost.Asio documentation."send_buffer_size"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/send_buffer_size.htmlBoost.Asio documentation."receive_buffer_size"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/receive_buffer_size.htmlBoost.Asio documentation.
get_option(self, opt: string) β value
Gets an option from the socket. currently available options are:
"debug"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/debug.htmlBoost.Asio documentation."send_buffer_size"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/send_buffer_size.htmlBoost.Asio documentation."receive_buffer_size"β check thehttps://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/socket_base/receive_buffer_size.htmlBoost.Asio documentation.
(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 theFIONREADIO control command. peek before u leap, bestie πβ¨
π FUNCTION FLAGS π
peekβ thehttps://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/reference/socket_base/message_peek.htmlflag with same name in Boost.Asio :
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
- nixos 26.05: emilua 0.12.1
- nixpkgs unstable: emilua 0.12.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms