<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/concurrency_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,13 +4,18 @@ static void response_send_chunk(connection_t *c, const char *ptr, size_t len)
 {
   /* chunk too big, split it in smaller chunks and send each separately */
   if (len &gt;= BUFFER_MAX_LEN) {
-    size_t i, size = BUFFER_MAX_LEN - 1, slices = len / size + 1;
+    size_t size   = BUFFER_MAX_LEN - 1;
+    size_t slices = len / size + 1;
+    size_t i, offset = 0;
     
     for (i = 0; i &lt; slices; ++i) {
+      /* last slice can be smaller */
       if (i == slices - 1)
         size = len % size;
       
-      response_send_chunk(c, (char *) ptr + i * size, size);
+      response_send_chunk(c, (char *) ptr + offset, size);
+      
+      offset += size;      
     }
     
     return;
@@ -25,9 +30,8 @@ static void response_send_chunk(connection_t *c, const char *ptr, size_t len)
   /* If we have a good sized chunk of data to send, try to send it right away.
    * This allows streaming by going for a shot in the even loop to drain the buffer if possisble,
       this way, the chunk is sent if the socket is writable.*/
-  if (c-&gt;write_buffer.len - c-&gt;write_buffer.offset &gt;= STREAM_SIZE) {
+  if (c-&gt;write_buffer.len - c-&gt;write_buffer.offset &gt;= STREAM_SIZE)
     ev_loop(c-&gt;loop, EVLOOP_ONESHOT | EVLOOP_NONBLOCK);    
-  }
 }
 
 static void response_send_status(connection_t *c, const int status)</diff>
      <filename>ext/thin_backend/response.c</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,12 @@ class App
   end
 end
 
+class DummyApp &lt; App
+  def process(env)
+    &quot;&quot;    
+  end
+end
+
 class EchoApp &lt; App
   def process(env)
     if env['REQUEST_METHOD'] == 'GET'</diff>
      <filename>spec/apps.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,9 +29,9 @@ describe Thin::Backends::Turbo, &quot;server&quot; do
       body.should == 'ohhithere!'
     end
   end
-    
+  
   it &quot;should handle big body (stored in memory)&quot; do
-    data = ['X' * 1024] * (80 + 31)
+    data = [rand_data(1024)] * (80 + 31)
     expected_size = data.join.size
     
     POST(&quot;/&quot;, data) do
@@ -45,7 +45,7 @@ describe Thin::Backends::Turbo, &quot;server&quot; do
   end
   
   it &quot;should handle very big body (stored to tempfile)&quot; do
-    data = ['X' * 1024] * 1024
+    data = [rand_data(1024)] * 1024
     expected_size = data.join.size
     
     POST(&quot;/&quot;, data) do</diff>
      <filename>spec/server_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/apps'
 require 'spec'
 require 'thread'
 require 'timeout'
+require 'digest/sha1'
 
 module ThinTurboServer
   ADDRESS = '0.0.0.0'
@@ -138,7 +139,15 @@ module HttpSpecDSL
     end
 end
 
+module Helpers
+  def rand_data(min, max=min)
+    count = min + ((rand(max)+1)).to_i
+    (Digest::SHA1.hexdigest(rand(count * 100).to_s) * (count / 39))[0, max]
+  end  
+end
+
 Spec::Runner.configure do |config|
   config.include ThinTurboServer
   config.include HttpSpecDSL
+  config.include Helpers
 end
\ No newline at end of file</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ba8f86c952e337db6e5f079337a1cd7c092151cf</id>
    </parent>
  </parents>
  <author>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </author>
  <url>http://github.com/macournoyer/thin-turbo/commit/dcd2777871649b18854dd6c213d3f1741307fc90</url>
  <id>dcd2777871649b18854dd6c213d3f1741307fc90</id>
  <committed-date>2008-05-24T20:39:20-07:00</committed-date>
  <authored-date>2008-05-24T20:39:20-07:00</authored-date>
  <message>Fix bug in size of last chunk when response is splitted in several slices to send.
Add tests for cucurrency.</message>
  <tree>9b525718492fbeddee9284808d6557fc05284267</tree>
  <committer>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </committer>
</commit>
