lib/pitchfork.rb in pitchfork-0.2.0 vs lib/pitchfork.rb in pitchfork-0.3.0

- old
+ new

@@ -55,19 +55,17 @@ else require ru Object.const_get(File.basename(ru, '.rb').capitalize) end - case ENV["RACK_ENV"] - when "development" - Rack::Builder.new do - use(Rack::Lint) - run inner_app - end.to_app - else - inner_app - end + Rack::Builder.new do + use(Rack::ContentLength) + use(Pitchfork::Chunked) + use(Rack::Lint) if ENV["RACK_ENV"] == "development" + use(Rack::TempfileReaper) + run inner_app + end.to_app end end # returns an array of strings representing TCP listen socket addresses # and Unix domain socket paths. This is useful for use with @@ -134,19 +132,55 @@ current_thread[key] = parent_thread[key] end parent_thread.thread_variables.each do |variable| current_thread.thread_variable_set(variable, parent_thread.thread_variable_get(variable)) end - - fork(&block) + Process.fork(&block) end.value end + + def self.fork_sibling(&block) + if REFORKING_AVAILABLE + # We double fork so that the new worker is re-attached back + # to the master. + # This requires either PR_SET_CHILD_SUBREAPER which is exclusive to Linux 3.4 + # or the master to be PID 1. + if middle_pid = Process.fork # parent + # We need to wait(2) so that the middle process doesn't end up a zombie. + Process.wait(middle_pid) + else # first child + clean_fork(&block) # detach into a grand child + exit + end + else + clean_fork(&block) + end + + nil # it's tricky to return the PID + end + + def self.time_now(int = false) + Process.clock_gettime(Process::CLOCK_MONOTONIC, int ? :second : :float_second) + end # :startdoc: end # :enddoc: -%w( - const socket_helper stream_input tee_input mem_info children message http_parser - refork_condition configurator tmpio http_response worker http_server -).each do |s| - require_relative "pitchfork/#{s}" -end +require 'pitchfork/pitchfork_http' + +Pitchfork::REFORKING_AVAILABLE = Pitchfork::CHILD_SUBREAPER_AVAILABLE || Process.pid == 1 + +require_relative "pitchfork/const" +require_relative "pitchfork/socket_helper" +require_relative "pitchfork/stream_input" +require_relative "pitchfork/tee_input" +require_relative "pitchfork/mem_info" +require_relative "pitchfork/children" +require_relative "pitchfork/message" +require_relative "pitchfork/chunked" +require_relative "pitchfork/http_parser" +require_relative "pitchfork/refork_condition" +require_relative "pitchfork/configurator" +require_relative "pitchfork/tmpio" +require_relative "pitchfork/http_response" +require_relative "pitchfork/worker" +require_relative "pitchfork/http_server"