ip.tcp.acceptor
local a = ip.tcp.acceptor.new()
a:open('v4')
a:set_option('reuse_address', true)
a:bind('127.0.0.1', 8080)
a:listen()
while true do
local s = a:accept()
spawn(function()
my_client_handler(s)
end)
end
Functions
open(self, address_family: "v4"|"v6"|ip.address)
Open the acceptor.
address_family
can be either "v4"
or "v6"
. If you provide an ip.address
object, the appropriate value will be inferred.
set_option(self, opt: string, val)
Set an option on the acceptor.
Currently available options are:
"reuse_address"
"enable_connection_aborted"
"debug"
"v6_only"
get_option(self, opt: string) → value
Get an option from the acceptor.
Currently available options are:
"reuse_address"
"enable_connection_aborted"
"debug"
"v6_only"
listen(self [, backlog: integer])
Place the acceptor into the state where it will listen for new connections.
backlog
is the maximum length of the queue of pending connections. If not
provided, an implementation defined maximum length will be used.
accept(self) → ip.tcp.socket
Initiate an accept operation and blocks current fiber until it completes or errs.
close(self)
Close the acceptor.
Forward the call to the function with same name in Boost.Asio:
Any asynchronous accept operations will be cancelled immediately.
A subsequent call to open() is required before the acceptor can again be used to again perform socket accept operations.
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.
assign(self, address_family: "v4"|"v6"|ip.address, fd: file_descriptor)
Assign an existing native acceptor to self
.
address_family
can be either "v4"
or "v6"
. If you provide an ip.address
object, the appropriate value will be inferred.
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 accept operations to finish immediately, and the handlers for cancelled operations will be passed the
boost::asio::error::operation_aborted
error. Ownership of the native acceptor is then transferred to the caller.