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. |
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.
Forward the call to the 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)
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.
Forward the call to the 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.
release(self) → file_descriptor
Release ownership of the native descriptor implementation.
Forward the call to the 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: 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:
"debug"
"send_buffer_size"
"receive_buffer_size"