lib/async/dns/server.rb in async-dns-1.0.0 vs lib/async/dns/server.rb in async-dns-1.1.0
- old
+ new
@@ -39,12 +39,10 @@
#
def initialize(endpoints = DEFAULT_ENDPOINTS, origin: '.', logger: Async.logger)
@endpoints = endpoints
@origin = origin
@logger = logger
-
- @handlers = []
end
# Records are relative to this origin:
attr_accessor :origin
@@ -104,38 +102,31 @@
# Setup all specified interfaces and begin accepting incoming connections.
def run(*args)
@logger.info "Starting Async::DNS server (v#{Async::DNS::VERSION})..."
- setup_handlers if @handlers.empty?
-
Async::Reactor.run do |task|
- @handlers.each do |handler|
+ fire(:setup)
+
+ Async::IO::Endpoint.each(@endpoints) do |endpoint|
task.async do
- handler.run(*args)
+ endpoint.bind do |socket|
+ case socket.type
+ when Socket::SOCK_DGRAM
+ @logger.info "<> Listening for datagrams on #{socket.local_address.inspect}"
+ DatagramHandler.new(self, socket).run
+ when Socket::SOCK_STREAM
+ @logger.info "<> Listening for connections on #{socket.local_address.inspect}"
+ StreamHandler.new(self, socket).run
+ else
+ raise ArgumentError.new("Don't know how to handle #{address}")
+ end
+ end
end
end
fire(:start)
end
end
- private
-
- def setup_handlers
- fire(:setup)
-
- Async::IO::Endpoint.each(@endpoints) do |endpoint|
- case endpoint.socket_type
- when Socket::SOCK_DGRAM
- @logger.info "<> Listening for datagrams on #{endpoint.inspect}"
- @handlers << DatagramHandler.new(self, endpoint)
- when Socket::SOCK_STREAM
- @logger.info "<> Listening for connections on #{endpoint.inspect}"
- @handlers << StreamHandler.new(self, endpoint)
- else
- raise ArgumentError.new("Don't know how to handle #{address}")
- end
- end
- end
end
end