diff options
author | Eric Wong <e@80x24.org> | 2015-12-13 12:19:00 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-12-13 12:29:43 +0000 |
commit | d3cf61b05d9507e7b6ea5a1a1192e107a8612049 (patch) | |
tree | 7e150cbc3177d58941aa3f26017627ac006b13aa /lib/dtas/process.rb | |
parent | e751a396e43f07f15d9b639a850c0c8cbebf9539 (diff) | |
download | dtas-d3cf61b05d9507e7b6ea5a1a1192e107a8612049.tar.gz |
Ruby 2.3 will have `exception: false' support in socket-related classes. Additionally, 2.3 will implement the existing IO#*_nonblock methods more efficiently than before by avoiding the hash allocation necessary for keywords. For users on older Rubies, we'll continue supporting them with compatibility wrappers; even Ruby 1.9.3 users (for now).
Diffstat (limited to 'lib/dtas/process.rb')
-rw-r--r-- | lib/dtas/process.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/dtas/process.rb b/lib/dtas/process.rb index f5f9a9e..8c46d9d 100644 --- a/lib/dtas/process.rb +++ b/lib/dtas/process.rb @@ -4,6 +4,7 @@ require 'io/wait' require 'shellwords' require_relative '../dtas' require_relative 'xs' +require_relative 'nonblock' # process management helpers module DTAS::Process # :nodoc: @@ -86,12 +87,13 @@ module DTAS::Process # :nodoc: cmd, opts = env, cmd env = {} end - r, w = IO.pipe + buf = '' + r, w = DTAS::Nonblock.pipe opts = opts.merge(out: w) r.binmode no_raise = opts.delete(:no_raise) if err_str = opts.delete(:err_str) - re, we = IO.pipe + re, we = DTAS::Nonblock.pipe re.binmode opts[:err] = we end @@ -105,12 +107,11 @@ module DTAS::Process # :nodoc: begin readable = IO.select(want.keys) or next readable[0].each do |io| - begin - want[io] << io.read_nonblock(2000) - rescue Errno::EAGAIN - # spurious wakeup, bytes may be zero - rescue EOFError - want.delete(io) + case rv = io.read_nonblock(2000, buf, exception: false) + when :wait_readable # spurious wakeup, bytes may be zero + when nil then want.delete(io) + else + want[io] << rv end end end until want.empty? |