sleepy_penguin.git  about / heads / tags
Linux I/O events for Ruby
blob d749158a02a1b3bca5fe8bf149f31420a5c4c85a 662 bytes (raw)
$ git show pu:test/test_epoll_io.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
require_relative 'helper'
require 'fcntl'
require 'socket'
require 'thread'

class TestEpollIO < Test::Unit::TestCase
  include SleepyPenguin

  def setup
    @rd, @wr = IO.pipe
    @epio = Epoll::IO.new(nil)
  end

  def test_add_wait
    @epio.epoll_ctl(Epoll::CTL_ADD, @wr, Epoll::OUT)
    ev = []
    @epio.epoll_wait { |events, obj| ev << [ events, obj ] }
    assert_equal([[Epoll::OUT, @wr]], ev)
  end

  class EpSub < Epoll::IO
    def self.new
      super(:CLOEXEC)
    end
  end

  def test_subclass
    tmp = EpSub.new
    assert_equal Fcntl::FD_CLOEXEC, tmp.fcntl(Fcntl::F_GETFD)
    assert_nil tmp.close
  end
end if defined?(SleepyPenguin::Epoll)

git clone https://yhbt.net/sleepy_penguin.git