Class: Mongrel::HttpServer

Inherits:
Object
  • Object
show all
Defined in:
lib/revactor/mongrel.rb

Overview

Mongrel’s HttpServer, monkeypatched to run on top of Revactor and using Actors for concurrency.

Instance Method Summary collapse

Constructor Details

#initialize(host, port, num_processors = 950, throttle = 0, timeout = 60) ⇒ HttpServer

Returns a new instance of HttpServer.



22
23
24
25
26
27
28
29
30
# File 'lib/revactor/mongrel.rb', line 22

def initialize(host, port, num_processors=950, throttle=0, timeout=60)
  @socket = Revactor::TCP.listen(host, port)
  @classifier = URIClassifier.new
  @host = host
  @port = port
  @throttle = throttle
  @num_processors = num_processors
  @timeout = timeout
end

Instance Method Details

#reap_dead_workers(reason = 'unknown') ⇒ Object

Clean up after any dead workers



64
65
66
67
# File 'lib/revactor/mongrel.rb', line 64

def reap_dead_workers(reason = 'unknown')
  # FIXME This should signal all workers to die
  0
end

#runObject

Runs the thing. Returns the Thread the server is running in.



59
60
61
# File 'lib/revactor/mongrel.rb', line 59

def run
  @acceptor = Thread.new { start }
end

#startObject

Start Mongrel. This method executes the Mongrel event loop, and will not return until interrupted or explicitly stopped.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/revactor/mongrel.rb', line 34

def start
  begin
    while true
      begin
        client = @socket.accept
        actor = Actor.spawn client, &method(:process_client)
        actor[:started_on] = Time.now
      rescue Interrupt, StopServer
        break
      rescue Errno::ECONNABORTED
        # client closed the socket even before accept
        client.close rescue nil
      rescue Object => e
        STDERR.puts "#{Time.now}: Unhandled listen loop exception #{e.inspect}."
        STDERR.puts e.backtrace.join("\n")
      end
    end
    graceful_shutdown
  ensure
    @socket.close
    # STDERR.puts "#{Time.now}: Closed socket."
  end
end