about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/yahns/http_response.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index 8a4bd6a..a520216 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -54,16 +54,20 @@ module Yahns::HttpResponse # :nodoc:
   end
 
   def wbuf_maybe(wbuf, rv, alive)
-    case rv # trysendfile return value
-    when nil
-      case alive
-      when :ignore
-        @state = alive
-      when Yahns::StreamFile
-        @state = alive
-        :wait_writable
-      when true, false
-        http_response_done(alive)
+    case rv # wbuf_write return value
+    when nil # all done
+      begin
+        case alive
+        when :ignore # hijacked
+          @state = alive
+        when Yahns::StreamFile
+          @state = alive
+          :wait_writable
+        when true, false
+          http_response_done(alive)
+        end
+      ensure
+        wbuf.wbuf_close(self)
       end
     else
       @state = wbuf