Sha256: 04d1ab0ee3e23f61ddad3f61b73f4fe90b9ce3518fb92c05aae6af93120d3df1

Contents?: true

Size: 707 Bytes

Versions: 1

Compression:

Stored size: 707 Bytes

Contents

require_relative '../handler'
require_relative '../message'

module Kamerling
  module Server
    class Sock
      attr_reader :addr

      def initialize(addr:, handler: Handler.new)
        @addr    = addr
        @handler = handler
      end

      def join
        thread.join
      end

      def start
        @thread = Thread.new { run_loop }
        wait_till_started
        self
      end

      def stop
        thread.exit.join
      end

      attr_reader :handler, :thread
      private     :handler, :thread

      private

      def handle(input, client_addr)
        handler.handle Message.parse(input), client_addr
      rescue Message::UnknownType
        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.3 lib/kamerling/server/sock.rb