Async::BusSourceAsyncBusServer

class Server

Represents a server that accepts async-bus connections.

Definitions

def initialize(endpoint = nil, **options)

Initialize a new server.

Signature

parameter endpoint IO::Endpoint

The endpoint to listen on.

parameter options Hash

Additional options for connections.

Implementation

def initialize(endpoint = nil, **options)
	@endpoint = endpoint || Protocol.local_endpoint
	@options = options
end

def accept(&block)

Accept incoming connections.

Signature

yields {|connection| ...}

Block called with each new connection.

Implementation

def accept(&block)
	@endpoint.accept do |peer|
		connection = Protocol::Connection.server(peer, **@options)
		
		connected!(connection, &block)
		
		yield connection if block_given?
		
		connection.run
	ensure
		connection&.close
	end
end