* [ANN] Ruby mogilefs-client 3.9.0
@ 2015-06-25 11:20 5% Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-06-25 11:20 UTC (permalink / raw)
To: mogile, mogilefs-client-public
Not much interesting, just minor improvements and a test bugfix
for Ruby-trunk users.
shortlog of changes since v3.8.0:
* test/test_fresh.rb: fix breakage from Ruby-trunk r50118
* use monotonic clock if possible on Ruby 2.1+
* avoid defineclass instructions for empty classes
* HACKING: minor documentation updates
* mogilefs/socket/pure_ruby: use IO#wait_*able
rdoc :: http://bogomips.org/mogilefs-client/
list :: mogilefs-client-public@bogomips.org
list-cc :: mogile@googlegroups.com
list-archive :: http://bogomips.org/mogilefs-client-public/
git clone git://bogomips.org/mogilefs-client.git
^ permalink raw reply [relevance 5%]
* [PATCH] mogilefs/socket/pure_ruby: use IO#wait_*able
@ 2015-06-24 1:56 7% Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-06-24 1:56 UTC (permalink / raw)
To: mogilefs-client-public; +Cc: Eric Wong
IO#wait_*able methods may use the more efficient ppoll syscall under
Linux to avoid performance penalties with high-numbered FDs. Use
them if available. IO#wait_readable has been around since the 1.8
days at least, and IO#wait_writable was added in Ruby 2.0.0
---
lib/mogilefs/socket/pure_ruby.rb | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/mogilefs/socket/pure_ruby.rb b/lib/mogilefs/socket/pure_ruby.rb
index 8833d22..7530a40 100644
--- a/lib/mogilefs/socket/pure_ruby.rb
+++ b/lib/mogilefs/socket/pure_ruby.rb
@@ -1,5 +1,6 @@
# -*- encoding: binary -*-
# internal implementation details here, do not rely on them in your code
+require 'io/wait'
class MogileFS::Socket < Socket
include MogileFS::SocketCommon
@@ -15,16 +16,20 @@ class MogileFS::Socket < Socket
def self.tcp(host, port, timeout = 5)
sock = start(host, port)
- unless IO.select(nil, [ sock ], nil, timeout)
+ unless sock.wait_writable(timeout)
sock.close
raise MogileFS::Timeout, 'socket connect timeout'
end
sock
end
+ def wait_writable(timeout)
+ IO.select(nil, [ self ], nil, timeout)
+ end unless self.instance_methods.include?(:wait_writable) # Ruby <2.0.0
+
def timed_read(len, dst = "", timeout = 5)
begin
- IO.select([self], nil, nil, timeout) or unreadable_socket!(timeout)
+ wait_readable(timeout) or unreadable_socket!(timeout)
return read_nonblock(len, dst)
rescue Errno::EAGAIN
rescue EOFError
@@ -34,7 +39,7 @@ class MogileFS::Socket < Socket
def timed_peek(len, dst, timeout = 5)
begin
- IO.select([self], nil, nil, timeout) or unreadable_socket!(timeout)
+ wait_readable(timeout) or unreadable_socket!(timeout)
rc = recv_nonblock(len, Socket::MSG_PEEK)
return rc.empty? ? nil : dst.replace(rc)
rescue Errno::EAGAIN
@@ -61,8 +66,7 @@ class MogileFS::Socket < Socket
buf = buf.slice(rc, buf.bytesize)
end
rescue Errno::EAGAIN
- IO.select(nil, [self], nil, timeout) or
- request_truncated!(written, expect, timeout)
+ wait_writable(timeout) or request_truncated!(written, expect, timeout)
end while true
end
end
--
EW
^ permalink raw reply related [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-06-24 1:56 7% [PATCH] mogilefs/socket/pure_ruby: use IO#wait_*able Eric Wong
2015-06-25 11:20 5% [ANN] Ruby mogilefs-client 3.9.0 Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/mogilefs-client.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).