diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-11 15:55:04 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-11 15:55:04 -0800 |
commit | b2c478eb88f442adb44b1fbe21ee25c1d368ae89 (patch) | |
tree | cc51c4e8b31307b0bcdfbb5a7a158d0886d159d0 | |
parent | 890b3904c770955cdb0a70864060f99786a4f402 (diff) | |
download | mogilefs-client-b2c478eb88f442adb44b1fbe21ee25c1d368ae89.tar.gz |
Exceptions are expensive, and Errno::EAGAIN is especially so in MRI 1.9.2+, so avoid generating too many of them. This is the whole reason kgio exists, after all.
-rw-r--r-- | lib/mogilefs/socket/pure_ruby.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/mogilefs/socket/pure_ruby.rb b/lib/mogilefs/socket/pure_ruby.rb index df8dfb9..24d576a 100644 --- a/lib/mogilefs/socket/pure_ruby.rb +++ b/lib/mogilefs/socket/pure_ruby.rb @@ -24,9 +24,9 @@ class MogileFS::Socket < Socket def timed_read(len, dst = "", timeout = 5) begin + IO.select([self], nil, nil, timeout) or unreadable_socket! return read_nonblock(len, dst) rescue Errno::EAGAIN - IO.select([self], nil, nil, timeout) or unreadable_socket! rescue EOFError return end while true @@ -34,10 +34,10 @@ class MogileFS::Socket < Socket def timed_peek(len, dst, timeout = 5) begin + IO.select([self], nil, nil, timeout) or unreadable_socket! rc = recv_nonblock(len, Socket::MSG_PEEK) return rc.empty? ? nil : dst.replace(rc) rescue Errno::EAGAIN - IO.select([self], nil, nil, timeout) or unreadable_socket! rescue EOFError dst.replace("") return |