Permalink
Browse files

Add Dalli::Server::KSocket#read_available to drain read buffer

  • Loading branch information...
1 parent 05f378a commit baeab3d0a4812646e227adf2a9dc9b5985a38316 @tmm1 tmm1 committed Nov 28, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/dalli/socket.rb
View
28 lib/dalli/socket.rb
@@ -35,6 +35,22 @@ def readfull(count)
value
end
+ def read_available
+ value = ''
+ loop do
+ ret = kgio_tryread(1024)
+ case ret
+ when nil
+ raise EOFError, 'end of stream'
+ when :wait_readable
+ break
+ else
+ value << ret
+ end
+ end
+ value
+ end
+
end
if ::Kgio.respond_to?(:wait_readable=)
@@ -76,5 +92,17 @@ def readfull(count)
value
end
+ def read_available
+ value = ''
+ loop do
+ begin
+ value << read_nonblock(1024)
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK
+ break
+ end
+ end
+ value
+ end
+
end
end

0 comments on commit baeab3d

Please sign in to comment.