about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-12 21:11:34 +0000
committerEric Wong <e@80x24.org>2016-07-12 21:13:21 +0000
commitc97b5254d6cc50264786270cdd09ed9485a5bec6 (patch)
treef349dffba552e07c2a0db462452d5006321e2290
parent946171bbc2e681cbab93863069767dd0fa4b6844 (diff)
downloadyahns-c97b5254d6cc50264786270cdd09ed9485a5bec6.tar.gz
And explain why this is doable for StringIO and not TmpIO,
which is file-backed.
-rw-r--r--lib/yahns/wbuf_lite.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb
index 2da5349..1902ce7 100644
--- a/lib/yahns/wbuf_lite.rb
+++ b/lib/yahns/wbuf_lite.rb
@@ -108,6 +108,12 @@ class Yahns::WbufLite # :nodoc:
   end
 
   def wbuf_abort
-    @tmpio = @tmpio.close if @tmpio
+    # we can safely truncate since this is a StringIO, we cannot do this
+    # with a real file because zero-copy with sendfile means truncating
+    # a while could clobber in-flight data
+    if @tmpio
+      @tmpio.truncate(0)
+      @tmpio = @tmpio.close
+    end
   end
 end