Ruby mogilefs-client dev/users discussion/patches/bugs/help/...
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: mogilefs-client-public@bogomips.org
Subject: [PATCH] socket/pure_ruby: fix Ruby 1.8 compatibility
Date: Wed,  4 Nov 2015 21:43:16 +0000	[thread overview]
Message-ID: <20151104214316.8841-1-e@80x24.org> (raw)

For non-kgio users, IO#wait_readable did not appear until Ruby 2.0.
Additionally, optimistically perform reads before waiting because
EOF handling behavior differs in current revisions of Ruby 2.3.0dev.
---
 lib/mogilefs/socket/pure_ruby.rb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/mogilefs/socket/pure_ruby.rb b/lib/mogilefs/socket/pure_ruby.rb
index 7530a40..e74bbef 100644
--- a/lib/mogilefs/socket/pure_ruby.rb
+++ b/lib/mogilefs/socket/pure_ruby.rb
@@ -23,15 +23,15 @@ class MogileFS::Socket < Socket
     sock
   end
 
-  def wait_writable(timeout)
+  def wait_writable(timeout = nil)
     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
-      wait_readable(timeout) or unreadable_socket!(timeout)
       return read_nonblock(len, dst)
     rescue Errno::EAGAIN
+      wait(timeout) or unreadable_socket!(timeout)
     rescue EOFError
       return
     end while true
@@ -39,10 +39,10 @@ class MogileFS::Socket < Socket
 
   def timed_peek(len, dst, timeout = 5)
     begin
-      wait_readable(timeout) or unreadable_socket!(timeout)
       rc = recv_nonblock(len, Socket::MSG_PEEK)
       return rc.empty? ? nil : dst.replace(rc)
     rescue Errno::EAGAIN
+      wait(timeout) or unreadable_socket!(timeout)
     rescue EOFError
       dst.replace("")
       return
-- 
EW


                 reply	other threads:[~2015-11-04 21:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/mogilefs-client/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151104214316.8841-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=mogilefs-client-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).