diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-02 02:06:19 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-02 02:06:19 +0000 |
commit | 4b8cc437c502e5fda86ac5935baf69ec5a585e74 (patch) | |
tree | e3249207ab89ed9eb5807c0732bc0eb79abd9960 /lib/mogilefs/socket_common.rb | |
parent | ec29cbf28b2fa3a0155462f8ee927265f9fc3d94 (diff) | |
download | mogilefs-client-4b8cc437c502e5fda86ac5935baf69ec5a585e74.tar.gz |
This will need further refactoring
Diffstat (limited to 'lib/mogilefs/socket_common.rb')
-rw-r--r-- | lib/mogilefs/socket_common.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/mogilefs/socket_common.rb b/lib/mogilefs/socket_common.rb index 7ab733c..567e715 100644 --- a/lib/mogilefs/socket_common.rb +++ b/lib/mogilefs/socket_common.rb @@ -3,6 +3,7 @@ require "socket" module MogileFS::SocketCommon attr_reader :mogilefs_addr + attr_accessor :mogilefs_size def post_init(host, port) @mogilefs_addr = "#{host}:#{port}" @@ -38,4 +39,16 @@ module MogileFS::SocketCommon end end while true end + + def read(size, buf = "", timeout = 5) + timed_read(size, buf, timeout) or return # nil/EOF + + while size > buf.bytesize + tmp ||= "" + timed_read(size - buf.bytesize, tmp, timeout) or return buf # truncated + buf << tmp + end + + buf # full read + end end |