<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>benchmark/app.rb</filename>
    </added>
    <added>
      <filename>benchmark/servers/ebb.rb</filename>
    </added>
    <added>
      <filename>benchmark/servers/mongrel.rb</filename>
    </added>
    <added>
      <filename>benchmark/servers/thin-turbo.rb</filename>
    </added>
    <added>
      <filename>benchmark/servers/thin.rb</filename>
    </added>
    <added>
      <filename>script/app.ru</filename>
    </added>
    <added>
      <filename>script/start</filename>
    </added>
    <added>
      <filename>tasks/gem.rake</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -10,13 +10,12 @@ New and ultra-turbo-crazy-fast backend for Thin
 
 === Usage
 
- thin start -rthin-turbo -BThin::Backends::Turbo
+ thin start -r lib/thin-turbo -b Thin::Backends::Turbo ...
 
 === License
 Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.
 
 === Credits
-
 Thin is copyright Marc-Andre Cournoyer &lt;macournoyer@gmail.com&gt;
 
 Get help at http://groups.google.com/group/thin-ruby/</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,7 @@
 RUBY_1_9 = RUBY_VERSION =~ /^1\.9/
 WIN      = (RUBY_PLATFORM =~ /mswin|cygwin/)
 SUDO     = (WIN ? &quot;&quot; : &quot;sudo&quot;)
+THIN_TURBO_VERSION  = '0.1.0'
 
 require 'rake'
 require 'rake/clean'</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,12 @@
 require 'rubygems'
-require 'rack'
 
 class Benchmarker
   PORT          = 7000
   ADDRESS       = '0.0.0.0'
   TMP_POST_FILE = &quot;/tmp/bench-post-file&quot;
-  SERVERS       = %w(Mongrel EMongrel Ebb Thin Thin-Turbo)
+  SERVERS       = %w(mongrel ebb thin thin-turbo)
   
   def initialize(method, range, options={})
-    @app        = App.new
     @method     = method
     @range      = range
 
@@ -47,28 +45,9 @@ class Benchmarker
   end
   
   private
-    def start_server(handler_name)
+    def start_server(name)
       @server = fork do
-        [STDOUT, STDERR].each { |o| o.reopen &quot;/dev/null&quot; }
-
-        case handler_name
-        when 'EMongrel'
-          require 'swiftcore/evented_mongrel'
-          Rack::Handler::Mongrel.run @app, :Host =&gt; ADDRESS, :Port =&gt; PORT
-        when 'Thin'
-          require 'thin'
-          Rack::Handler::Thin.run @app, :Host =&gt; ADDRESS, :Port =&gt; PORT
-        when 'Thin-Turbo'
-          require File.dirname(__FILE__) + &quot;/../lib/thin-turbo&quot;
-          b = Thin::Backend.new(ADDRESS, PORT, @app)
-          b.start
-        when 'Ebb'
-          require 'ebb'
-          Ebb.start_server(@app, :threaded_processing =&gt; false, :port =&gt; PORT)
-        else
-          handler = Rack::Handler.const_get(handler_name)
-          handler.run @app, :Host =&gt; ADDRESS, :Port =&gt; PORT
-        end
+        exec &quot;ruby #{File.dirname(__FILE__)}/servers/#{name}.rb&quot;
       end
     
       sleep 2
@@ -136,27 +115,3 @@ class Benchmarker
       [total, virtual, real]
     end
 end
-
-class App
-  MIN_SIZE = 1024
-  
-  def initialize
-    @calls = 0
-  end
-  
-  def call(env)
-    status  = 200
-    body    = []
-    request = Rack::Request.new(env)
-    @calls += 1
-    
-    sleep request.params['wait'].to_i if request.params['wait'] &amp;&amp; @calls % 10 == 0
-    
-    body   &lt;&lt; 'X' * (request.params['size'] || MIN_SIZE).to_i
-    body   &lt;&lt; &quot;\r\n&quot;
-    
-    headers = { 'Content-Type' =&gt; 'text/plain', 'Content-Length' =&gt; body.join.size.to_s }
-    
-    [status, headers, body]
-  end
-end</diff>
      <filename>benchmark/benchmarker.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ require 'optparse'
 
 MB = 1024 ** 2
 CONCURRENCY_RANGE = [1, 10, 50]
-FILE_RANGE        = [1 * MB, 5 * MB, 10 * MB]
+FILE_RANGE        = [1 * MB] #, 5 * MB , 10 * MB]
 
 options = {
   :keep_alive    =&gt; false,
@@ -15,7 +15,8 @@ method = ARGV[0].to_sym
 OptionParser.new do |opts|
   opts.banner = &quot;Usage: #{$0} (concurrency|upload|download) [options]&quot;
 
-  opts.on(&quot;-r&quot;, &quot;--range&quot;, &quot;Range used to run benchmark&quot;)       { |r| range = eval(&quot;[#{r}]&quot;) }
+  opts.on(&quot;-n NUM&quot;, &quot;--requests&quot;, &quot;Number of requests&quot;)         { |n| options[:requests] = n }
+  opts.on(&quot;-r EVAL&quot;, &quot;--range&quot;, &quot;Range used to run benchmark&quot;)  { |r| range = eval(&quot;[#{r}]&quot;) }
   opts.on(&quot;-k&quot;, &quot;--keep-alive&quot;, &quot;Use persistent connections&quot;)   { options[:keep_alive] = true }
   
   opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;Show this message&quot;)     { puts opts; exit }</diff>
      <filename>benchmark/run</filename>
    </modified>
    <modified>
      <diff>@@ -31,29 +31,30 @@ static void backend_accept_cb(EV_P_ struct ev_io *watcher, int revents)
 
 /* public api */
 
-VALUE backend_init(VALUE self, VALUE address, VALUE port, VALUE app)
+VALUE backend_set_app(VALUE self, VALUE app)
 {
   backend_t *backend = NULL;
   DATA_GET(self, backend_t, backend);
-    
-  backend-&gt;address = RSTRING_PTR(address);
-  backend-&gt;port = FIX2INT(port);
-  backend-&gt;app = app;
-  
-  backend-&gt;local_addr.sin_family = AF_INET;
-  backend-&gt;local_addr.sin_port = htons(backend-&gt;port);
-  backend-&gt;local_addr.sin_addr.s_addr = inet_addr(backend-&gt;address);
   
-  backend-&gt;loop = ev_default_loop(0);
+  backend-&gt;app = app;
   
-  return self;
+  return app;
 }
 
-VALUE backend_listen(VALUE self)
+VALUE backend_listen_on_port(VALUE self, VALUE address, VALUE port)
 {
   backend_t *backend = NULL;
   DATA_GET(self, backend_t, backend);
   int sock_flags;
+  
+  backend-&gt;address = RSTRING_PTR(address);
+  backend-&gt;port = FIX2INT(port);
+  
+  backend-&gt;local_addr.sin_family = AF_INET;
+  backend-&gt;local_addr.sin_port = htons(backend-&gt;port);
+  backend-&gt;local_addr.sin_addr.s_addr = inet_addr(backend-&gt;address);
+  
+  backend-&gt;loop = ev_default_loop(0);
 
   if ((backend-&gt;fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
     rb_sys_fail(&quot;socket&quot;);
@@ -95,9 +96,11 @@ VALUE backend_close(VALUE self)
   backend_t *backend = NULL;
   DATA_GET(self, backend_t, backend);
   
-  backend-&gt;open = 0;
-  ev_io_stop(backend-&gt;loop, &amp;backend-&gt;accept_watcher);
-  close(backend-&gt;fd);
+  if (backend-&gt;open) {
+    backend-&gt;open = 0;
+    ev_io_stop(backend-&gt;loop, &amp;backend-&gt;accept_watcher);
+    close(backend-&gt;fd);    
+  }
   
   return Qtrue;
 }
@@ -129,12 +132,12 @@ VALUE backend_alloc(VALUE klass)
 void backend_define(void)
 {
   /* Plug our C stuff into the Ruby world */
-  VALUE mThin = rb_define_module(&quot;Thin&quot;);
-  VALUE cBackend = rb_define_class_under(mThin, &quot;Backend&quot;, rb_cObject);
+  VALUE mThin = rb_define_module_under(rb_define_module(&quot;Thin&quot;), &quot;Backends&quot;);
+  VALUE cBackend = rb_define_class_under(mThin, &quot;Turbo&quot;, rb_cObject);
   
   rb_define_alloc_func(cBackend, backend_alloc);
-  rb_define_method(cBackend, &quot;initialize&quot;, backend_init, 3);
-  rb_define_protected_method(cBackend, &quot;listen&quot;, backend_listen, 0);
+  rb_define_method(cBackend, &quot;app=&quot;, backend_set_app, 1);
+  rb_define_protected_method(cBackend, &quot;listen_on_port&quot;, backend_listen_on_port, 2);
   rb_define_protected_method(cBackend, &quot;loop!&quot;, backend_loop, 0);
   rb_define_protected_method(cBackend, &quot;close&quot;, backend_close, 0);
 }</diff>
      <filename>ext/thin_backend/backend.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+require 'rubygems'
 require 'thin_backend'
 
 class Thin::Backend </diff>
      <filename>ext/thin_backend/test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'rubygems'
 require 'thin'
 
-require File.dirname(__FILE__) + &quot;/thin/backends/turbo&quot;
\ No newline at end of file
+require File.dirname(__FILE__) + &quot;/../ext/thin_backend/thin_backend&quot;
+require File.dirname(__FILE__) + &quot;/thin/backends/turbo&quot;</diff>
      <filename>lib/thin-turbo.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,26 +1,71 @@
-require 'thin_backend'
-
 module Thin
-  class Backend
-    def start
-      listen
-      puts 'Listening on 0.0.0.0:4000'
-
-      trap('INT') { stop }
+  module Backends
+    class Turbo
+      # Server serving the connections throught the backend
+      attr_accessor :server
+      
+      # Address and port on which the server is listening for connections.
+      attr_accessor :host, :port
+      
+      # Maximum time for incoming data to arrive
+      attr_accessor :timeout
+      
+      # Maximum number of file or socket descriptors that the server may open.
+      attr_accessor :maximum_connections
+      
+      # Maximum number of connections that can be persistent
+      attr_accessor :maximum_persistent_connections
+      
+      # Allow using threads in the backend.
+      attr_writer :threaded
+      def threaded?; @threaded end
+      
+      # Number of persistent connections currently opened
+      attr_accessor :persistent_connection_count
+      
+      def initialize(host, port, options={})
+        @host = host
+        @port = port.to_i
+      end
+      
+      def start
+        self.app = @server.app
+        listen_on_port(@host, @port)
 
-      @running = true
-      loop! while @running
-      close
-    end
-
-    def stop
-      puts 'Stopping ...'
-      @running = false
-    end
+        @running = true
+        loop! while @running
+        close
+      end
 
-    def log_error(ex=$!)
-      puts &quot;!! Unexpected error while processing request: #{ex.message}&quot;
-      puts ex.backtrace.join(&quot;\n&quot;) if ex.backtrace
+      def stop
+        @running = false
+      end
+      alias :stop! :stop
+    
+      def config
+      end
+    
+      def running?
+        @running
+      end
+    
+      def empty?
+        false # TODO
+      end
+    
+      def size
+        0 # TODO
+      end
+      
+      def to_s
+        &quot;#{@host}:#{@port} (turbo)&quot;
+      end
+      
+      protected
+        def log_error(ex=$!)
+          puts &quot;!! Unexpected error while processing request: #{ex.message}&quot;
+          puts ex.backtrace.join(&quot;\n&quot;) if ex.backtrace
+        end
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/thin/backends/turbo.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,7 +23,7 @@ def ext_task(name)
     cd ext_dir do
       sh(WIN ? 'nmake' : 'make')
     end
-    cp ext_bundle, 'lib/'
+    # cp ext_bundle, 'lib/'
   end
 end
 </diff>
      <filename>tasks/ext.rake</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>tasks/stats.rake</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>07afc6a61a74045dbf715180c7d9fc602e9db676</id>
    </parent>
  </parents>
  <author>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </author>
  <url>http://github.com/macournoyer/thin-turbo/commit/4caece803a6309f6377248865d874fc51dedaaba</url>
  <id>4caece803a6309f6377248865d874fc51dedaaba</id>
  <committed-date>2008-04-09T19:26:24-07:00</committed-date>
  <authored-date>2008-04-09T19:26:24-07:00</authored-date>
  <message>Fully working as a Thin backend.
Do not fork to start servers in benchmark, split in script.</message>
  <tree>a0831970f62e77bf705b9ce6f1badfc34002ae4f</tree>
  <committer>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </committer>
</commit>
