diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-10 12:38:16 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-10 12:38:16 +0000 |
commit | 91c1bb9d449206ce57036fb9c458f44b0bffc9d2 (patch) | |
tree | 1adeee4d3bd9e1c4834ca040b3999fbf312798d2 /test/socket | |
parent | 8a44158f5a29862ba1ddc66b413f158c27cf51ce (diff) | |
download | ruby-91c1bb9d449206ce57036fb9c458f44b0bffc9d2.tar.gz ruby-91c1bb9d449206ce57036fb9c458f44b0bffc9d2.tar.xz ruby-91c1bb9d449206ce57036fb9c458f44b0bffc9d2.zip |
* ext/socket/lib/socket.rb (Socket.udp_server_sockets): new method.
(Socket.udp_server_loop_on): new method.
(Socket.udp_server_loop): new method
(Socket.ip_sockets_port0): extracted from tcp_server_sockets_port0.
(Socket::UDPSource): new class.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/socket')
-rw-r--r-- | test/socket/test_socket.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index cb5454024..5b2b7b41d 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -225,4 +225,38 @@ class TestSocket < Test::Unit::TestCase end + def test_udp_server + begin + ip_addrs = Socket.ip_address_list + rescue NotImplementedError + end + + sockets = Socket.udp_server_sockets(0) + port = sockets.first.local_address.ip_port + + th = Thread.new { + Socket.udp_server_loop_on(sockets) {|msg, msg_src| + break if msg == "exit" + rmsg = Marshal.dump([msg, msg_src.remote_address, msg_src.local_address]) + msg_src.reply rmsg + } + } + + ip_addrs.each {|ai| + Addrinfo.udp(ai.ip_address, port).connect {|s| + msg1 = "<<<#{ai.inspect}>>>" + s.sendmsg msg1 + msg2, addr = s.recvmsg + msg2, remote_address, local_address = Marshal.load(msg2) + assert_equal(msg1, msg2) + assert_equal(ai.ip_address, addr.ip_address) + } + } + ensure + if th + Addrinfo.udp("127.0.0.1", port).connect {|s| s.sendmsg "exit" } + th.join + end + end + end if defined?(Socket) |