From 32481c4126c09a659dd240a44fe27a2af513dd52 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 9 Dec 2004 01:19:30 +0000 Subject: [PATCH] * test/socket/test_socket.rb (test_setsockopt): use SO_LINGER instead of SO_BINDTODEVICE. fixed: [ruby-dev:25133] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 17 ++++++++----- test/socket/test_socket.rb | 49 ++++++++++++++++++++++++++++++++++---- test/socket/test_tcp.rb | 4 +++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 700fc3ed17..8d59324eaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,29 +1,34 @@ +Thu Dec 9 10:19:18 2004 Nobuyoshi Nakada + + * test/socket/test_socket.rb (test_setsockopt): use SO_LINGER instead + of SO_BINDTODEVICE. fixed: [ruby-dev:25133] + Thu Dec 9 03:08:36 2004 Hidetoshi NAGAI * ext/tcltklib/tcltklib.c (ip_init): set root-win title to "ruby" when - the running script is '-e one-liner' or '-' (stdin). + the running script is '-e one-liner' or '-' (stdin). * ext/tcltklib/extconf.rb: add find_library("#{lib}#{ver}",..) for - stub libs + stub libs * ext/tk/lib/tk/textmark.rb: TkTextMarkCurrent and TkTextMarkAnchor - have a wrong parent class. + have a wrong parent class. - * ext/tk/lib/tk/dialog.rb: rename TkDialog2 --> TkDialogObj and + * ext/tk/lib/tk/dialog.rb: rename TkDialog2 --> TkDialogObj and TkWarning2 --> TkWarningObj (old names are changed to alias names) * ext/tk/lib/tk/dialog.rb: bug fix of treatment of 'prev_command' option and hashes for configuration * ext/tk/lib/tk/dialog.rb: add TkDialogObj#name to return the - button name + button name * ext/tk/lib/tk/radiobutton.rb: rename enbugged method value() ==> get_value() and value=(val) ==> set_value(val). * ext/tk/lib/tk/menu.rb: add TkMenu.new_menuspec - * ext/tk/lib/tk/menu.rb: add alias (TkMenuButton = TkMenubutton, + * ext/tk/lib/tk/menu.rb: add alias (TkMenuButton = TkMenubutton, TkOptionMenuButton = TkOptionMenubutton) * ext/tk/lib/tk/event.rb: new method aliases (same as option keys of diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index 1d2ba04bfd..c436484dde 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -5,15 +5,56 @@ rescue LoadError end class TestBasicSocket < Test::Unit::TestCase + def inet_stream + sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) + yield sock + ensure + assert_raise(IOError) {sock.close} + end + + def test_getsockopt + inet_stream do |s| + n = s.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE) + assert_equal([Socket::SOCK_STREAM].pack("i"), n) + n = s.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR) + assert_equal([0].pack("i"), n) + val = Object.new + class << val; self end.send(:define_method, :to_int) { + s.close + Socket::SO_TYPE + } + assert_raise(IOError) { + n = s.getsockopt(Socket::SOL_SOCKET, val) + } + end + end + def test_setsockopt # [ruby-dev:25039] - s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) + s = nil + linger = [0, 0].pack("ii") + val = Object.new class << val; self end.send(:define_method, :to_str) { s.close - "eth0" + linger } - assert_raise(IOError) { - s.setsockopt(Socket::SOL_SOCKET, Socket::SO_BINDTODEVICE, val) + inet_stream do |s| + assert_equal(0, s.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger)) + + assert_raise(IOError) { + s.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, val) + } + end + + val = Object.new + class << val; self end.send(:define_method, :to_int) { + s.close + Socket::SO_LINGER } + inet_stream do |s| + assert_raise(IOError) { + s.setsockopt(Socket::SOL_SOCKET, val, linger) + } + end end end if defined?(Socket) diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb index a1657f027d..596919082f 100644 --- a/test/socket/test_tcp.rb +++ b/test/socket/test_tcp.rb @@ -9,7 +9,7 @@ class TestTCPSocket < Test::Unit::TestCase def test_recvfrom # [ruby-dev:24705] c = s = nil svr = TCPServer.new("localhost", 0) - Thread.new { + th = Thread.new { c = svr.accept ObjectSpace.each_object(String) {|s| s.replace "a" if s.length == 0x10000 and !s.frozen? @@ -21,5 +21,7 @@ class TestTCPSocket < Test::Unit::TestCase assert_raise(RuntimeError, SocketError) { sock.recvfrom(0x10000) } + ensure + th.join end end if defined?(TCPSocket)