[前][次][番号順一覧][スレッド一覧]

ruby-changes:34179

From: akr <ko1@a...>
Date: Fri, 30 May 2014 23:50:48 +0900 (JST)
Subject: [ruby-changes:34179] akr:r46260 (trunk): Close FDs.

akr	2014-05-30 23:50:42 +0900 (Fri, 30 May 2014)

  New Revision: 46260

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=46260&view=revision

  Log:
    Close FDs.

  Modified files:
    trunk/test/webrick/test_filehandler.rb
    trunk/test/webrick/test_httpresponse.rb
Index: test/webrick/test_httpresponse.rb
===================================================================
--- test/webrick/test_httpresponse.rb	(revision 46259)
+++ test/webrick/test_httpresponse.rb	(revision 46260)
@@ -48,64 +48,66 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpresponse.rb#L48
     end
 
     def test_send_body_io
-      body_r, body_w = IO.pipe
+      IO.pipe {|body_r, body_w|
+        body_w.write 'hello'
+        body_w.close
 
-      body_w.write 'hello'
-      body_w.close
+        @res.body = body_r
 
-      @res.body = body_r
+        IO.pipe {|r, w|
 
-      r, w = IO.pipe
+          @res.send_body w
 
-      @res.send_body w
+          w.close
 
-      w.close
-
-      assert_equal 'hello', r.read
+          assert_equal 'hello', r.read
+        }
+      }
     end
 
     def test_send_body_string
       @res.body = 'hello'
 
-      r, w = IO.pipe
-
-      @res.send_body w
+      IO.pipe {|r, w|
+        @res.send_body w
 
-      w.close
+        w.close
 
-      assert_equal 'hello', r.read
+        assert_equal 'hello', r.read
+      }
     end
 
     def test_send_body_string_io
       @res.body = StringIO.new 'hello'
 
-      r, w = IO.pipe
-
-      @res.send_body w
+      IO.pipe {|r, w|
+        @res.send_body w
 
-      w.close
+        w.close
 
-      assert_equal 'hello', r.read
+        assert_equal 'hello', r.read
+      }
     end
 
     def test_send_body_io_chunked
       @res.chunked = true
 
-      body_r, body_w = IO.pipe
+      IO.pipe {|body_r, body_w|
 
-      body_w.write 'hello'
-      body_w.close
+        body_w.write 'hello'
+        body_w.close
 
-      @res.body = body_r
+        @res.body = body_r
 
-      r, w = IO.pipe
+        IO.pipe {|r, w|
+          @res.send_body w
 
-      @res.send_body w
+          w.close
 
-      w.close
-
-      r.binmode
-      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+          r.binmode
+          assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+        }
+      }
     end
 
     def test_send_body_string_chunked
@@ -113,14 +115,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpresponse.rb#L115
 
       @res.body = 'hello'
 
-      r, w = IO.pipe
-
-      @res.send_body w
+      IO.pipe {|r, w|
+        @res.send_body w
 
-      w.close
+        w.close
 
-      r.binmode
-      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+        r.binmode
+        assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+      }
     end
 
     def test_send_body_string_io_chunked
@@ -128,14 +130,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpresponse.rb#L130
 
       @res.body = StringIO.new 'hello'
 
-      r, w = IO.pipe
-
-      @res.send_body w
+      IO.pipe {|r, w|
+        @res.send_body w
 
-      w.close
+        w.close
 
-      r.binmode
-      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+        r.binmode
+        assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+      }
     end
   end
 end
Index: test/webrick/test_filehandler.rb
===================================================================
--- test/webrick/test_filehandler.rb	(revision 46259)
+++ test/webrick/test_filehandler.rb	(revision 46260)
@@ -14,10 +14,15 @@ class WEBrick::TestFileHandler < Test::U https://github.com/ruby/ruby/blob/trunk/test/webrick/test_filehandler.rb#L14
   end
 
   def get_res_body(res)
-    if defined? res.body.read
-      res.body.read
+    body = res.body
+    if defined? body.read
+      begin
+        body.read
+      ensure
+        body.close
+      end
     else
-      res.body
+      body
     end
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]