Class: Celluloid::DNS::Server

Inherits:
Object
  • Object
show all
Includes:
IO
Defined in:
lib/celluloid/dns/server.rb

Constant Summary collapse

MAX_PACKET_SIZE =

Maximum UDP packet we’ll accept

512

Instance Method Summary collapse

Constructor Details

#initialize(addr, port, &block) ⇒ Server

Returns a new instance of Server.



9
10
11
12
13
14
15
16
17
# File 'lib/celluloid/dns/server.rb', line 9

def initialize(addr, port, &block)
  @block = block
  
  # Create a non-blocking Celluloid::IO::UDPSocket
  @socket = UDPSocket.new
  @socket.bind(addr, port)
  
  async.run
end

Instance Method Details

#runObject



19
20
21
22
23
24
# File 'lib/celluloid/dns/server.rb', line 19

def run
  loop do
    data, (_, port, addr) = @socket.recvfrom(MAX_PACKET_SIZE)
    @block.call Request.new(addr, port, @socket, data)
  end
end