about summary refs log tree commit homepage
path: root/lib/dtas/sigevent
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-13 12:19:00 +0000
committerEric Wong <e@80x24.org>2015-12-13 12:29:43 +0000
commitd3cf61b05d9507e7b6ea5a1a1192e107a8612049 (patch)
tree7e150cbc3177d58941aa3f26017627ac006b13aa /lib/dtas/sigevent
parente751a396e43f07f15d9b639a850c0c8cbebf9539 (diff)
downloaddtas-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/sigevent')
-rw-r--r--lib/dtas/sigevent/pipe.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/dtas/sigevent/pipe.rb b/lib/dtas/sigevent/pipe.rb
index 4f42909..5dd01a6 100644
--- a/lib/dtas/sigevent/pipe.rb
+++ b/lib/dtas/sigevent/pipe.rb
@@ -3,11 +3,13 @@
 
 # used in various places for safe wakeups from IO.select via signals
 # A fallback for non-Linux systems lacking the "sleepy_penguin" RubyGem
+require_relative 'nonblock'
 class DTAS::Sigevent # :nodoc:
   attr_reader :to_io
 
   def initialize
-    @to_io, @wr = IO.pipe
+    @to_io, @wr = DTAS::Nonblock.pipe
+    @rbuf = ''
   end
 
   def signal
@@ -15,11 +17,10 @@ class DTAS::Sigevent # :nodoc:
   end
 
   def readable_iter
-    begin
-      @to_io.read_nonblock(11)
+    case @to_io.read_nonblock(11, @rbuf, exception: false)
+    when :wait_readable then return :wait_readable
+    else
       yield self, nil # calls DTAS::Process.reaper
-    rescue Errno::EAGAIN
-      return :wait_readable
     end while true
   end