For the latest stable version, please use Emilua API 0.10!

unix.datagram_socket

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:slice(1, nread))

Functions

new() → unix.datagram_socket

new()                    (1)
new(fd: file_descriptor) (2)
1 Default constructor.
2 Converts a file descriptor into an unix.datagram_socket object.

pair() → unix.datagram_socket, unix.datagram_socket

Create a pair of connected sockets.

open(self)

Open the socket.

bind(self, pathname: filesystem.path)

Bind the socket to the given local endpoint.

connect(self, pathname: filesystem.path)

Set the default destination address so datagrams can be sent using send() without specifying a destination address.

disconnect(self)

Dissolve the socket’s association by resetting the socket’s peer address (i.e. connect(3) will be called with an AF_UNSPEC address).

close(self)

Close the socket.

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)

Disable sends or receives on the socket.

what can be one of the following:

"receive"

Shutdown the receive side of the socket.

"send"

Shutdown the send side of the socket.

"both"

Shutdown both send and receive on the socket.

cancel(self)

Cancel all asynchronous operations associated with the acceptor.

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)

Assign an existing native socket to self.

release(self) → file_descriptor

Release ownership of the native descriptor implementation.

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: integer]) → integer

Receive a datagram and blocks current fiber until it completes or errs.

Returns the number of bytes read.

flags is 0 or an or-combination of values from unix.message_flag(3em).

receive_from(self, buffer: byte_span[, flags: integer]) → integer, filesystem.path

Receive a datagram and blocks current fiber until it completes or errs.

Returns the number of bytes read plus the pathname of the remote sender of the datagram.

flags is 0 or an or-combination of values from unix.message_flag(3em).

send(self, buffer: byte_span[, flags: integer]) → integer

Send data on the datagram socket and blocks current fiber until it completes or errs.

Returns the number of bytes written.

flags is 0 or an or-combination of values from unix.message_flag(3em).

The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.

send_to(self, buffer: byte_span, pathname: filesystem.path[, flags: integer]) → integer

Send a datagram to the specified remote endpoint and blocks current fiber until it completes or errs.

Returns the number of bytes written.

flags is 0 or an or-combination of values from unix.message_flag(3em).

receive_with_fds(self, buffer: byte_span, maxfds: integer) → integer, file_descriptor[]

Receive a datagram and blocks current fiber until it completes or errs.

Returns the number of bytes read plus the table containing the fds read.

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

Receive a datagram and blocks 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.

send_with_fds(self, buffer: byte_span, fds: file_descriptor[]) → integer

Send data on the datagram socket and blocks current fiber until it completes or errs.

Returns the number of bytes written.

The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.

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

Send a datagram to the specified remote endpoint and blocks current fiber until it completes or errs.

Returns the number of bytes written.

set_option(self, opt: string, val)

Set an option on the socket.

Currently available options are:

get_option(self, opt: string) → value

Get an option from the socket.

Currently available options are:

io_control(self, command: string[, …​])

Perform an IO control command on the socket.

Currently available commands are:

"bytes_readable"

Expects no arguments. Get the amount of data that can be read without blocking. Implements the FIONREAD IO control command.

Properties

is_open: boolean

Whether the socket is open.

local_path: filesystem.path

The local address endpoint of the socket.

remote_path: filesystem.path

The remote address endpoint of the socket.