Permalink
Browse files

Remove nonblocking option

  • Loading branch information...
1 parent 4105345 commit 7c8485261cd8cd54710105bef1ce246b7fb505a7 @darkhelmet darkhelmet committed Dec 31, 2010
Showing with 14 additions and 16 deletions.
  1. +3 −3 lib/mongrel2/connection.rb
  2. +11 −13 lib/rack/handler/mongrel2.rb
@@ -6,8 +6,8 @@ module Mongrel2
class Connection
CTX = ZMQ::Context.new(1)
- def initialize(uuid, sub, pub, block = true)
- @uuid, @sub, @pub, @block = uuid, sub, pub, block
+ def initialize(uuid, sub, pub)
+ @uuid, @sub, @pub = uuid, sub, pub
# Connect to receive requests
@reqs = CTX.socket(ZMQ::PULL)
@@ -20,7 +20,7 @@ def initialize(uuid, sub, pub, block = true)
end
def recv
- msg = @reqs.recv_string(@block ? 0 : ZMQ::NOBLOCK)
+ msg = @reqs.recv_string(0)
msg.nil? ? nil : Request.parse(msg)
end
@@ -9,29 +9,27 @@ def run(app, options = {})
options = {
:recv => 'tcp://127.0.0.1:9997' || ENV['RACK_MONGREL2_RECV'],
:send => 'tcp://127.0.0.1:9996' || ENV['RACK_MONGREL2_SEND'],
- :uuid => ENV['RACK_MONGREL2_UUID'],
- :block => ENV['RACK_MONGREL2_NONBLOCK'].to_s.match(/1|t(?:rue)?|y(?:es)/i).nil?
+ :uuid => ENV['RACK_MONGREL2_UUID']
}.merge(options)
raise ArgumentError.new('Must specify an :uuid or set RACK_MONGREL2_UUID') if options[:uuid].nil?
- conn = ::Mongrel2::Connection.new(options[:uuid], options[:recv], options[:send], options[:block])
+ conn = ::Mongrel2::Connection.new(options[:uuid], options[:recv], options[:send])
running = true
- # This doesn't work at all until zmq fixes their shit
- # %w(INT TERM KILL).each do |sig|
- # trap(sig) do
- # conn.close
- # running = false
- # end
- # end
+ # This doesn't work at all until zmq fixes their shit (in 2.1.x I think), but trap it now anyway.
+ %w(INT TERM KILL).each do |sig|
+ trap(sig) do
+ conn.close
+ running = false
+ end
+ end
while running
- req = conn.recv
- sleep(1) and next if req.nil? && options[:block]
+ req = conn.recv rescue nil
next if req.nil? || req.disconnect?
- return if !running
+ break if !running
script_name = ENV['RACK_RELATIVE_URL_ROOT'] || req.headers['PATTERN'].split('(', 2).first.gsub(/\/$/, '')
env = {

0 comments on commit 7c84852

Please sign in to comment.