From: Paul Brannan Date: 2008-03-25T00:43:07+09:00 Subject: Re: Thread#raise, Thread#kill, and timeout.rb are unsafe On Thu, Mar 20, 2008 at 07:21:06AM +0900, MenTaLguY wrote: > Now, the question with IO and asynchronous exceptions in Ruby is > whether there is a good way to report a partial result? The existing API already returns the number of bytes successfully written for both IO#write and IO#syswrite. But how do we find out what caused the operation to be interrupted? Currently IO#write gives an exception: irb(main):001:0> r, w = IO.pipe => [#, #] irb(main):002:0> t = Thread.new { w.write("HELLO" * 20000) } => # irb(main):003:0> r.close => nil irb(main):004:0> t.join Errno::EPIPE: Broken pipe from (irb):2:in `write' from (irb):4:in `join' from (irb):4 and IO#syswrite gives the number of bytes written: irb(main):018:0> sock = TCPSocket.new('localhost', 2000) => # irb(main):019:0> t = Thread.new { p sock.syswrite("HELLO" * 200000) } => # irb(main):024:0> t.join 131072 => # I think the behavior of IO#syswrite is correct (because there is only one write(2) system call), but IO#write actually got *both* partial success *and* an exceptional condition, so what should its behavior be? Paul