From a5dc800d2e4b3a86466a03f45f64b97d29e4b11e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 4 Jul 2010 08:13:24 +0000 Subject: revactor: properly zero buffer on zero reads While we're at it, fix a comment, too. --- lib/rainbows/revactor.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/rainbows/revactor.rb') diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 021fc48..7a063ab 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -147,7 +147,8 @@ module Rainbows::Revactor # Revactor socket reads always return an unspecified amount, # sometimes too much def readpartial(length, dst = "") - return dst if length == 0 + return dst.replace("") if length == 0 + # always check and return from the userspace buffer first rbuf.size > 0 and return dst.replace(rbuf.read(length)) @@ -158,7 +159,7 @@ module Rainbows::Revactor # to avoid needlessly wasting memory bandwidth tmp.size <= length and return dst.replace(tmp) - # ugh, read returned too much, copy + reread to avoid slicing + # ugh, read returned too much rbuf << tmp[length, tmp.size] dst.replace(tmp[0, length]) end -- cgit v1.2.3-24-ge0c7