For the latest stable version, please use Emilua API 0.10! |
unix.stream_socket
local a, b = unix.stream_socket.pair()
spawn(function()
local buf = byte_span.new(1024)
local nread = b:read_some(buf)
print(buf:slice(1, nread))
end):detach()
local nwritten = stream.write_all(a, 'Hello World')
print(nwritten)
Functions
new() → unix.stream_socket
new() (1)
new(fd: file_descriptor) (2)
1 | Default constructor. |
2 | Converts a file descriptor into an unix.stream_socket object. |
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.
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.
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.
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.
connect(self, pathname: filesystem.path)
Initiate a connect operation and blocks current fiber until it completes or errs.
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).
read_some(self, buffer: byte_span) → integer
Read data from the stream socket and blocks current fiber until it completes or errs.
Returns the number of bytes read.
write_some(self, buffer: byte_span) → integer
Write data to the stream socket and blocks current fiber until it completes or errs.
Returns the number of bytes written.
receive_with_fds(self, buffer: byte_span, maxfds: integer) → integer, file_descriptor[]
Read data from the stream socket and blocks current fiber until it completes or errs.
Returns the number of bytes read + the table containing the fds
read.
send_with_fds(self, buffer: byte_span, fds: file_descriptor[]) → integer
Write data to the stream socket and blocks current fiber until it completes or errs.
Returns the number of bytes written.
fds are not closed and can be re-converted to some Emilua IO object if
so one wishes.
|
set_option(self, opt: string, val)
Set an option on the socket.
Currently available options are:
"send_low_watermark"
"send_buffer_size"
"receive_low_watermark"
"receive_buffer_size"
"debug"