diff options
author | delano <delano@solutious.com> | 2009-08-26 16:04:51 -0400 |
---|---|---|
committer | delano <delano@solutious.com> | 2009-08-26 16:04:51 -0400 |
commit | 351ccbece418e0bf2e807a6e2427b95348c90e08 (patch) | |
tree | f472d0974d133637336eaaf6429398b25d58cab6 | |
parent | a76e1f2840424dc909aeac0ca9803b38541cb17e (diff) | |
download | net-ssh-351ccbece418e0bf2e807a6e2427b95348c90e08.tar.gz |
Apply IO#select threading fix for Ruby 1.8 (exclude 1.9 and JRuby)
-rw-r--r-- | lib/net/ssh/transport/packet_stream.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/net/ssh/transport/packet_stream.rb b/lib/net/ssh/transport/packet_stream.rb index ff758a0..57c5dde 100644 --- a/lib/net/ssh/transport/packet_stream.rb +++ b/lib/net/ssh/transport/packet_stream.rb @@ -65,17 +65,24 @@ module Net; module SSH; module Transport end end - # A fix for an IO#select threading bug - # See: http://www.daniel-azuma.com/blog/view/z2ysbx0e4c3it9/ruby_1_8_7_io_select_threading_bug - MUTEX = Mutex.new - - # Returns true if the IO is available for reading, and false otherwise. - def available_for_read? - result = nil - MUTEX.synchronize do - result = IO.select([self], nil, nil, 0) + if RUBY_VERSION > '1.9' || RUBY_PLATFORM == 'java' + # Returns true if the IO is available for reading, and false otherwise. + def available_for_read? + result = IO.select([self], nil, nil, 0) + result && result.first.any? + end + else + # A fix for an IO#select threading bug in Ruby 1.8 + # See: http://net-ssh.lighthouseapp.com/projects/36253/tickets/1-ioselect-threading-bug-in-ruby-18 + MUTEX = Mutex.new + # Returns true if the IO is available for reading, and false otherwise. + def available_for_read? + result = nil + MUTEX.synchronize do + result = IO.select([self], nil, nil, 0) + end + result && result.first.any? end - result && result.first.any? end # Returns the next full packet. If the mode parameter is :nonblock (the |