Method: Thin::Server#initialize

Defined in:
lib/thin/server.rb

#initialize(*args, &block) ⇒ Server

Returns a new instance of Server.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/thin/server.rb', line 91

def initialize(*args, &block)
  host, port, options = DEFAULT_HOST, DEFAULT_PORT, {}
  
  # Guess each parameter by its type so they can be
  # received in any order.
  args.each do |arg|
    case arg
    when Fixnum, /^\d+$/ then port    = arg.to_i
    when String          then host    = arg
    when Hash            then options = arg
    else
      @app = arg if arg.respond_to?(:call)
    end
  end
  
  # Try to intelligently select which backend to use.
  @backend = select_backend(host, port, options)
  
  load_cgi_multipart_eof_fix
  
  @backend.server = self
  
  # Set defaults
  @backend.maximum_connections            = DEFAULT_MAXIMUM_CONNECTIONS
  @backend.maximum_persistent_connections = DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
  @backend.timeout                        = DEFAULT_TIMEOUT
  
  # Allow using Rack builder as a block
  @app = Rack::Builder.new(&block).to_app if block
  
  # If in debug mode, wrap in logger adapter
  @app = Rack::CommonLogger.new(@app) if Logging.debug?
  
  setup_signals unless options[:signals].class == FalseClass
end