--Multipart_Wed_Jul_31_16:42:36_2002-1
Content-Type: text/plain; charset=ISO-2022-JP

なかだです。

File::NONBLOCKを指定したIOでEWOULDBLOCKが発生すると、途中まで読
まれたデータがあっても失われてしまいます。

$ cat io/nonblock.rb
require "fcntl"
class IO
  def nonblock(nb)
    (fcntl(Fcntl::F_GETFL) & File::NONBLOCK) ! 
  end
  def nonblockb)
    f  cntl(Fcntl::F_GETFL)
    if nb
      f | ile::NONBLOCK
    else
      f & File::NONBLOCK
    end
    fcntl(Fcntl::F_SETFL, f)
  end
end

$ cat nbtest.rb
require 'io/nonblock'

open("|-", "r+") do |f|
  unless f
    STDOUT.sync  rue
    begin
      STDOUT.print "foo"
      sleep 3
      STDOUT.print "bar\n"
    rescue Errno::EPIPE
    end
    exit
  else
    f.nonblock  rue
    sleep 1
    p f.gets rescue p $!	# "foo"が読まれているが捨てられる
    f.nonblock  alse
    p f.eof?
    p f.gets			#"bar\n"
  end
end

添付のパッチのようにリトライする以外にも、Errno::EWOULDBLOCKに
読めたデータを持たせるという方法も考えられますが。


--Multipart_Wed_Jul_31_16:42:36_2002-1
Content-Type: text/x-diff; type=gzip; charset=US-ASCII
Content-Disposition: attachment; filename="nonblock.diff.gz"
Content-Transfer-Encoding: base64

H4sIAAAAAAACA+1VXW/aSBR9tn/FrSJFJrYLNh+lIKqmCYnYpVCRZKvdF8vY42DVsdHYhI1S
/vveO2OwCSZqtd239QPGM3funHvOuTOj2Gd/9yBM3nrq4N8/6uziBoIwYj2oe49pna/mT/WU
e/IP7WI8qpxlPGSPYXwPHF9pmMRgvbVatuqHQQDmCkwbzCWYXIxKcKZpij+K3YXfVjHYjYYN
Vrdnd3qNBpgNfBSZRNd1Gdm0MDKSkY1Wz272mk0ZqX78iHu03xst0OlldwBHwsQJgmiVLrTA
gGCZ8ZoKGxVU/TEJfVXncwcj1m6YOZy5vjuPmBYsa6oO+FyNxkM4C5Z9VX+WI4HvpCwDHvhp
X46EcQYBDAQ/cUJrcSJffun8NZxNtV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zxHKj9NdXrxj/CXbh+VsckpfYXyj/gMTk3RvCg0AAA
--Multipart_Wed_Jul_31_16:42:36_2002-1
Content-Type: text/plain; charset=ISO-2022-JP


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

--Multipart_Wed_Jul_31_16:42:36_2002-1--