Skip to content

Commit

Permalink
Remove nonblocking option
Browse files Browse the repository at this point in the history
  • Loading branch information
darkhelmet committed Dec 31, 2010
1 parent 4105345 commit 7c84852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/mongrel2/connection.rb
Expand Up @@ -6,8 +6,8 @@ module Mongrel2
class Connection class Connection
CTX = ZMQ::Context.new(1) CTX = ZMQ::Context.new(1)


def initialize(uuid, sub, pub, block = true) def initialize(uuid, sub, pub)
@uuid, @sub, @pub, @block = uuid, sub, pub, block @uuid, @sub, @pub = uuid, sub, pub


# Connect to receive requests # Connect to receive requests
@reqs = CTX.socket(ZMQ::PULL) @reqs = CTX.socket(ZMQ::PULL)
Expand All @@ -20,7 +20,7 @@ def initialize(uuid, sub, pub, block = true)
end end


def recv def recv
msg = @reqs.recv_string(@block ? 0 : ZMQ::NOBLOCK) msg = @reqs.recv_string(0)
msg.nil? ? nil : Request.parse(msg) msg.nil? ? nil : Request.parse(msg)
end end


Expand Down
24 changes: 11 additions & 13 deletions lib/rack/handler/mongrel2.rb
Expand Up @@ -9,29 +9,27 @@ def run(app, options = {})
options = { options = {
:recv => 'tcp://127.0.0.1:9997' || ENV['RACK_MONGREL2_RECV'], :recv => 'tcp://127.0.0.1:9997' || ENV['RACK_MONGREL2_RECV'],
:send => 'tcp://127.0.0.1:9996' || ENV['RACK_MONGREL2_SEND'], :send => 'tcp://127.0.0.1:9996' || ENV['RACK_MONGREL2_SEND'],
:uuid => ENV['RACK_MONGREL2_UUID'], :uuid => ENV['RACK_MONGREL2_UUID']
:block => ENV['RACK_MONGREL2_NONBLOCK'].to_s.match(/1|t(?:rue)?|y(?:es)/i).nil?
}.merge(options) }.merge(options)


raise ArgumentError.new('Must specify an :uuid or set RACK_MONGREL2_UUID') if options[:uuid].nil? 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 running = true


# This doesn't work at all until zmq fixes their shit # 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| %w(INT TERM KILL).each do |sig|
# trap(sig) do trap(sig) do
# conn.close conn.close
# running = false running = false
# end end
# end end


while running while running
req = conn.recv req = conn.recv rescue nil
sleep(1) and next if req.nil? && options[:block]
next if req.nil? || req.disconnect? 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(/\/$/, '') script_name = ENV['RACK_RELATIVE_URL_ROOT'] || req.headers['PATTERN'].split('(', 2).first.gsub(/\/$/, '')
env = { env = {
Expand Down

0 comments on commit 7c84852

Please sign in to comment.