Class: Rhino::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, sockets) ⇒ Server

Returns a new instance of Server.



6
7
8
9
# File 'lib/rhino/server.rb', line 6

def initialize(application, sockets)
  self.application = application
  self.sockets = sockets
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



3
4
5
# File 'lib/rhino/server.rb', line 3

def application
  @application
end

#socketsObject

Returns the value of attribute sockets.



4
5
6
# File 'lib/rhino/server.rb', line 4

def sockets
  @sockets
end

Instance Method Details

#monitorObject



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

def monitor
  selections, = IO.select(self.sockets)
  io, = selections

  begin
    socket, = io.accept
    http = Rhino::HTTP::new(socket, application)
    http.handle
  rescue Rhino::HTTP::Exception => exception
    Rhino.logger.log("EXCEPTION: #{exception.message}")
  rescue ::Errno::ECONNRESET
  rescue ::Errno::ENOTCONN
  rescue ::Errno::EPIPE
  rescue ::Errno::EPROTOTYPE
  ensure
    socket.close
  end
end

#runObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/rhino/server.rb', line 11

def run
  loop do
    begin
      monitor
    rescue Interrupt
      Rhino.logger.log("INTERRUPTED")
      return
    end
  end
end