From 7dd3d804e9199a201aa62b7f7e7c28ddeace99c5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 31 Mar 2009 00:37:49 -0700 Subject: Use {read,write}_nonblock on the pipe Instead of trusting sysread/syswrite to throw EAGAIN if the pipe is full (highly unlikely); just use non-blocking methods which are indeed non-blocking and don't care for the #blocking= method added to it. --- lib/unicorn.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 7ffc8a5..cbbb283 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -161,7 +161,6 @@ module Unicorn # this pipe is used to wake us up from select(2) in #join when signals # are trapped. See trap_deferred @rd_sig, @wr_sig = IO.pipe unless (@rd_sig && @wr_sig) - @rd_sig.nonblock = @wr_sig.nonblock = true mode = nil respawn = true @@ -262,16 +261,16 @@ module Unicorn begin ready = IO.select([@rd_sig], nil, nil, 1) ready && ready[0] && ready[0][0] or return - loop { @rd_sig.sysread(Const::CHUNK_SIZE) } + loop { @rd_sig.read_nonblock(Const::CHUNK_SIZE) } rescue Errno::EAGAIN, Errno::EINTR end end def awaken_master begin - @wr_sig.syswrite('.') # wakeup master process from IO.select - rescue Errno::EAGAIN # pipe is full, master should wake up anyways - rescue Errno::EINTR + @wr_sig.write_nonblock('.') # wakeup master process from IO.select + rescue Errno::EAGAIN, Errno::EINTR + # pipe is full, master should wake up anyways retry end end -- cgit v1.2.3-24-ge0c7