64: def initialize
65: @running = false
66: @awake = false
67: @wakeup_time = nil
68: @timers = []
69:
70: @io_arrays = [[], [], []]
71: @ios = Hash.new do |h, k| raise ArgumentError,
72: "invalid IO event: #{k}", caller(2) end
73: IO_STATES.each_with_index { |x, i| @ios[x] = @io_arrays[i] }
74:
75: @notify_src, @notify_snk = IO.pipe
76:
77:
78: @notify_src.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
79: @notify_snk.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
80:
81: @notify_src.will_block = false
82: @notify_snk.will_block = false
83:
84:
85:
86: monitor_io(@notify_src, :readable)
87: @notify_src.extend(Watchable)
88: @notify_src.on_readable do
89: begin
90: @notify_src.sysread(256)
91: rescue Errno::EAGAIN
92:
93: end
94: end
95: end