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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
require_relative 'em_test_helper'
class TestSockOpt < Test::Unit::TestCase
def setup
assert(!EM.reactor_running?)
@port = next_port
end
def teardown
assert(!EM.reactor_running?)
end
def test_set_sock_opt
omit_if(windows?)
omit_if(!EM.respond_to?(:set_sock_opt))
val = nil
test_module = Module.new do
define_method :post_init do
val = set_sock_opt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true
EM.stop
end
end
EM.run do
EM.start_server 'localhost', @port
EM.connect 'localhost', @port, test_module
end
assert_equal 0, val
end
def test_get_sock_opt
omit_if(windows?)
omit_if(!EM.respond_to?(:set_sock_opt))
val = nil
test_module = Module.new do
define_method :connection_completed do
val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_ERROR
EM.stop
end
end
EM.run do
EM.start_server 'localhost', @port
EM.connect 'localhost', @port, test_module
end
assert_equal "\0\0\0\0", val
end
end
|