lib/kamerling/server/sock.rb in kamerling-0.0.2 vs lib/kamerling/server/sock.rb in kamerling-0.0.3

- old
+ new

@@ -1,32 +1,40 @@ -module Kamerling module Server class Sock - attr_reader :addr +require_relative '../handler' +require_relative '../message' - def initialize addr: req(:addr), handler: Handler.new - @addr = addr - @handler = handler - end +module Kamerling + module Server + class Sock + attr_reader :addr - def join - thread.join - end + def initialize(addr:, handler: Handler.new) + @addr = addr + @handler = handler + end - def start - @thread = Thread.new { run_loop } - wait_till_started - self - end + def join + thread.join + end - def stop - thread.exit.join - end + def start + @thread = Thread.new { run_loop } + wait_till_started + self + end - attr_reader :handler, :thread - private :handler, :thread + def stop + thread.exit.join + end - private + attr_reader :handler, :thread + private :handler, :thread - def handle input, client_addr - handler.handle input, client_addr - rescue Handler::UnknownInput + private + + def handle(input, client_addr) + handler.handle Message.parse(input), client_addr + rescue Message::UnknownType + nil + end + end end -end end end +end