copy_stream_false_select.rb

Eric Wong, 05/13/2011 05:45 AM

Download (456 Bytes)

 
1
require "socket"
2
require "tempfile"
3
require "io/nonblock"
4
a, b = UNIXSocket.pair
5
b.nonblock = true
6
Tempfile.open("copy_stream_test") do |tmp|
7
  IO.copy_stream("/dev/zero", tmp.to_io, 1024 * 1024 * 30)
8
  tmp.flush
9
  tmp.rewind
10

    
11
  # maxes out CPU because we select() on tmp.fileno which always
12
  # returns true, and sendfile() always hits EAGAIN because we
13
  # only select() b.fileno for readability (not writability)
14
  nr = IO.copy_stream(tmp.to_io, b)
15
end