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/unix_server.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/unix_server.rb')
-rw-r--r-- | lib/dtas/unix_server.rb | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/dtas/unix_server.rb b/lib/dtas/unix_server.rb index e21a096..e11b0d7 100644 --- a/lib/dtas/unix_server.rb +++ b/lib/dtas/unix_server.rb @@ -58,12 +58,10 @@ class DTAS::UNIXServer # :nodoc: def readable_iter # we do not do anything with the block passed to us - begin - sock, _ = @to_io.accept_nonblock - @readers[DTAS::UNIXAccepted.new(sock)] = true - rescue Errno::ECONNABORTED # ignore this, it happens - rescue Errno::EAGAIN - return :wait_readable + case rv = accept_nonblock + when :wait_readable then return rv + else + @readers[DTAS::UNIXAccepted.new(rv[0])] = true end while true end @@ -88,9 +86,7 @@ class DTAS::UNIXServer # :nodoc: # - a consumer (e.g. DTAS::Sink) just became writable, but the # corresponding DTAS::Buffer was already readable in a previous # call. - when nil - io.close - when StandardError + when nil, StandardError io.close else raise "BUG: wait_ctl invalid: #{io} #{err.inspect}" @@ -117,4 +113,16 @@ class DTAS::UNIXServer # :nodoc: wait_ctl(io, io.readable_iter { |_io, msg| yield(_io, msg) }) end end + + if RUBY_VERSION.to_f >= 2.3 + def accept_nonblock + @to_io.accept_nonblock(exception: false) + end + else + def accept_nonblock + @to_io.accept_nonblock + rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO + :wait_readable + end + end end |