lib/rubydns.rb in rubydns-0.6.7 vs lib/rubydns.rb in rubydns-0.7.0

- old
+ new

@@ -18,18 +18,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'rubydns/version' -if RUBY_VERSION < "1.9" - require 'rubydns/extensions/string-1.8' -elsif RUBY_VERSION < "1.9.3" - require 'rubydns/extensions/string-1.9.2' -else - require 'rubydns/extensions/string-1.9.3' -end - require 'rubydns/message' require 'rubydns/server' require 'rubydns/resolver' require 'rubydns/handler' @@ -40,52 +32,18 @@ require 'rubydns/handler' module RubyDNS - # Run a server with the given rules. A number of options can be supplied: - # - # <tt>:interfaces</tt>:: A set of sockets or addresses as defined below. - # - # One important feature of DNS is the port it runs on. The <tt>options[:listen]</tt> - # allows you to specify a set of network interfaces and ports to run the server on. This - # must be a list of <tt>[protocol, interface address, port]</tt>. - # - # INTERFACES = [[:udp, "0.0.0.0", 5300]] - # RubyDNS::run_server(:listen => INTERFACES) do - # ... - # end - # - # You can specify already connected sockets if need be: - # - # socket = UDPSocket.new; socket.bind("0.0.0.0", 53) - # Process::Sys.setuid(server_uid) - # INTERFACES = [socket] - # - # The default interface is <tt>[[:udp, "0.0.0.0", 53]]</tt>. The server typically needs - # to run as root for this to work, since port 53 is privileged. - # + # Run a server with the given rules. def self.run_server (options = {}, &block) - server = RubyDNS::Server.new(&block) - server.logger.info "Starting RubyDNS server (v#{RubyDNS::VERSION})..." + server = RubyDNS::RuleBasedServer.new(&block) - options[:listen] ||= [[:udp, "0.0.0.0", 53], [:tcp, "0.0.0.0", 53]] - EventMachine.run do - server.fire(:setup) - - # Setup server sockets - options[:listen].each do |spec| - server.logger.info "Listening on #{spec.join(':')}" - if spec[0] == :udp - EventMachine.open_datagram_socket(spec[1], spec[2], UDPHandler, server) - elsif spec[0] == :tcp - EventMachine.start_server(spec[1], spec[2], TCPHandler, server) - end - end - - server.fire(:start) + server.run(options) end server.fire(:stop) end + + end