about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEvan Weaver <eweaver@twitter.com>2009-01-31 19:30:58 -0800
committerEvan Weaver <eweaver@twitter.com>2009-01-31 19:30:58 -0800
commitd3c75a987596a3249f0bbaa8de50b8a6046cb864 (patch)
treedf54f31b51e5631a928ccbfd3e33285be1bc27e5 /lib
parent914481b635b0c7baefaf7d955c3cd59af2fafeb0 (diff)
downloadunicorn-d3c75a987596a3249f0bbaa8de50b8a6046cb864.tar.gz
Diffstat (limited to 'lib')
-rw-r--r--lib/mongrel.rb33
-rw-r--r--lib/mongrel/cgi.rb2
2 files changed, 19 insertions, 16 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 0b90057..07fc36f 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -39,6 +39,10 @@ module Mongrel
     def logger
       @logger ||= Logger.new(STDERR)
     end
+    
+    def run(app, options = {})
+      HttpServer.new(app, options).start.join
+    end
   end
 
   # Used to stop the HttpServer via Thread.raise.
@@ -71,9 +75,11 @@ module Mongrel
     attr_reader :max_concurrent_threads
     
     DEFAULTS = {
-      :max_queued_threads => 20,
-      :max_concurrent_threads => 20,
-      :timeout => 60
+      :Max_queued_threads => 20,
+      :Max_concurrent_threads => 20,
+      :Timeout => 60,
+      :Host => '0.0.0.0',
+      :Port => 8080
     }
 
     # Creates a working server on host:port (strange things happen if port isn't a Number).
@@ -86,19 +92,16 @@ module Mongrel
     # way to deal with overload.  Other schemes involve still parsing the client's request
     # which defeats the point of an overload handling system.
     #
-    def initialize(host, port, app, options = {})
-      options = DEFAULTS.merge(options)
-
-      @socket = TCPServer.new(host, port)
-      if defined?(Fcntl::FD_CLOEXEC)
-        @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
-      end
-      @host, @port, @app = host, port, app
+    def initialize(app, options = {})
+      @app = app      
       @workers = ThreadGroup.new
+      
+      (DEFAULTS.to_a + options.to_a).each do |key, value|
+        instance_variable_set("@#{key.to_s.downcase}", value)
+      end
 
-      @timeout = options[:timeout]
-      @max_queued_threads = options[:max_queued_threads]
-      @max_concurrent_threads = options[:max_concurrent_threads]
+      @socket = TCPServer.new(@host, @port)      
+      @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined?(Fcntl::FD_CLOEXEC)
     end
 
     # Does the majority of the IO processing.  It has been written in Ruby using
@@ -234,7 +237,7 @@ module Mongrel
     
     # Runs the thing.  It returns the thread used so you can "join" it.  You can also
     # access the HttpServer::acceptor attribute to get the thread later.
-    def start!
+    def start
       semaphore = Semaphore.new(@max_concurrent_threads)
       BasicSocket.do_not_reverse_lookup = true
 
diff --git a/lib/mongrel/cgi.rb b/lib/mongrel/cgi.rb
index ed6fcf0..05d2d54 100644
--- a/lib/mongrel/cgi.rb
+++ b/lib/mongrel/cgi.rb
@@ -173,7 +173,7 @@ module Mongrel
     
     # The stdoutput should be completely bypassed but we'll drop a warning just in case
     def stdoutput
-      Mongrel.logger.warn "WARNING: Your program is doing something not expected.  Please tell Zed that stdoutput was used and what software you are running.  Thanks."
+      Mongrel.logger.warn "WARNING: stdoutput used."
       @response.body
     end
   end