Class: Rhino::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rhino/launcher.rb

Overview

Handles the bootstrapping of the application (setting up sockets, building via rack, etc).

Usage:

launcher = Rhino.Launcher.new(5000, '0.0.0.0', reuseaddr, 64, './config.ru')
launcher.run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, bind, reuseaddr, backlog, config) ⇒ Launcher

Returns a new instance of Launcher.



17
18
19
20
21
22
23
# File 'lib/rhino/launcher.rb', line 17

def initialize(port, bind, reuseaddr, backlog, config)
  self.port = port
  self.bind = bind
  self.reuseaddr = reuseaddr
  self.backlog = backlog
  self.config = config
end

Instance Attribute Details

#backlogObject

Returns the value of attribute backlog.



13
14
15
# File 'lib/rhino/launcher.rb', line 13

def backlog
  @backlog
end

#bindObject

Returns the value of attribute bind.



12
13
14
# File 'lib/rhino/launcher.rb', line 12

def bind
  @bind
end

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/rhino/launcher.rb', line 14

def config
  @config
end

#portObject

Returns the value of attribute port.



11
12
13
# File 'lib/rhino/launcher.rb', line 11

def port
  @port
end

#reuseaddrObject

Returns the value of attribute reuseaddr.



15
16
17
# File 'lib/rhino/launcher.rb', line 15

def reuseaddr
  @reuseaddr
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rhino/launcher.rb', line 25

def run
  Rhino.logger.log("Rhino")
  Rhino.logger.log("#{bind}:#{port}")

  begin
    socket = Socket.new(:INET, :STREAM)
    socket.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, reuseaddr)
    socket.bind(Addrinfo.tcp(self.bind, self.port))
    socket.listen(self.backlog)

    server = Rhino::Server.new(application, [socket])
    server.run
  ensure
    socket.close
  end
end