Permalink
Browse files

Handle char vs byte and mixing syswrite with write properly

  • Loading branch information...
1 parent 8fdc274 commit 23257c8fdeb956f4770d014362f46c4534b1f517 @evanphx evanphx committed Nov 29, 2012
Showing with 13 additions and 2 deletions.
  1. +4 −0 lib/puma/compat.rb
  2. +9 −2 lib/puma/server.rb
View
@@ -4,4 +4,8 @@ class String
unless method_defined? :bytesize
alias_method :bytesize, :size
end
+
+ unless method_defined? :byteslice
+ alias_method :byteslice, :[]
+ end
end
View
@@ -569,8 +569,15 @@ def fast_write(io, str)
# Fast path.
return if n == str.bytesize
- # Otherwise go into slow path and use ruby's builtin write logic
- io.write str[n..-1]
+ pos = n
+ left = str.bytesize - n
+
+ until left == 0
+ n = io.syswrite str.byteslice(pos..-1)
+
+ pos += n
+ left -= n
+ end
end
private :fast_write
end

1 comment on commit 23257c8

glebm commented on 23257c8 Dec 9, 2012

Would be nice if this is released
Can't use trunk with Gemfile for some reason (on jruby)

Please sign in to comment.