class Dizby::ServiceWorker

Public Class Methods

new(server) click to toggle source
# File lib/dizby/worker/server.rb, line 11
def initialize(server)
  @server = server
  @thread = Thread.start { run }
end

Public Instance Methods

join() click to toggle source
# File lib/dizby/worker/server.rb, line 16
def join
  @thread.join if @thread
end

Private Instance Methods

accept_connection() click to toggle source
# File lib/dizby/worker/server.rb, line 36
def accept_connection
  connection = @server.accept
  return nil unless connection

  @server.add_uri_alias connection.remote_uri
  ConnectionWorker.new(@server, connection)
end
run() click to toggle source
# File lib/dizby/worker/server.rb, line 22
def run
  connections = []
  loop do
    conn = accept_connection
    connections << conn if conn
  end
rescue LocalServerShutdown
  @server.log.debug('Server shutdown')
ensure
  @server.close if @server.alive?

  connections.each(&:close)
end