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

ruby-changes:23177

From: naruse <ko1@a...>
Date: Wed, 4 Apr 2012 04:25:02 +0900 (JST)
Subject: [ruby-changes:23177] naruse:r35227 (trunk): * lib/ftp/ftp.rb (Net::FTP#close): close socket more gracefully.

naruse	2012-04-04 04:24:30 +0900 (Wed, 04 Apr 2012)

  New Revision: 35227

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

  Log:
    * lib/ftp/ftp.rb (Net::FTP#close): close socket more gracefully.
    
    * lib/ftp/ftp.rb (Net::BufferedSocket#shutdown): added.
    
    * test/net/ftp/test_ftp.rb (FTPTest#create_ftp_server): wait socket
      with shutdown and read.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35226)
+++ ChangeLog	(revision 35227)
@@ -1,3 +1,12 @@
+Wed Apr  4 01:48:35 2012  NARUSE, Yui  <naruse@r...>
+
+	* lib/ftp/ftp.rb (Net::FTP#close): close socket more gracefully.
+
+	* lib/ftp/ftp.rb (Net::BufferedSocket#shutdown): added.
+
+	* test/net/ftp/test_ftp.rb (FTPTest#create_ftp_server): wait socket
+	  with shutdown and read.
+
 Tue Apr  3 19:00:52 2012  NAKAMURA Usaku  <usa@r...>
 
 	* test/net/ftp/test_ftp.rb (FTPTest#create_ftp_server): should wait
@@ -140,7 +149,7 @@
 Thu Mar 29 07:45:36 2012  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_asn1.c: raise TypeError when trying to encode nil
-	  values for Primitive instances. 
+	  values for Primitive instances.
 	* test/openssl/test_asn1.rb: Assert consistent behavior when
 	  encoding nil values: Primitives raise TypeError, Constructives
 	  raise NoMethodError.
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 35226)
+++ lib/net/ftp.rb	(revision 35227)
@@ -932,7 +932,12 @@
     # a new connection with #connect.
     #
     def close
-      @sock.close if @sock and not @sock.closed?
+      if @sock and not @sock.closed?
+        @sock.shutdown(Socket::SHUT_WR)
+        @sock.read_timeout = 1
+        @sock.read
+        @sock.close
+      end
     end
 
     #
@@ -1055,7 +1060,7 @@
     end
 
     class BufferedSocket < BufferedIO
-      [:addr, :peeraddr, :send].each do |method|
+      [:addr, :peeraddr, :send, :shutdown].each do |method|
         define_method(method) { |*args|
           @io.__send__(method, *args)
         }
@@ -1067,7 +1072,8 @@
           return s.empty? ? nil : s
         else
           result = ""
-          while s = super(BUFSIZ, "", true)
+          while s = super(DEFAULT_BLOCKSIZE, "", true)
+            break if s.empty?
             result << s
           end
           return result
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 35226)
+++ test/net/ftp/test_ftp.rb	(revision 35227)
@@ -375,14 +375,10 @@
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
-      binary_data.scan(/.{1,1024}/nm).each_with_index do |s, i|
-        if i == 1
-          sleep(0.5)
-        else
-          sleep(0.1)
-        end
-        conn.print(s)
-      end
+      sleep(0.1)
+      conn.print(binary_data[0,1024])
+      sleep(0.5)
+      assert_raise(Errno::EPIPE){ conn.print(binary_data[1024, 1024]) }
       conn.close
       sock.print("226 Transfer complete.\r\n")
     }
@@ -406,7 +402,7 @@
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
-        ftp.close if ftp
+        ftp.close unless ftp.closed?
       end
     ensure
       server.close
@@ -591,7 +587,9 @@
         sock = server.accept
         begin
           yield(sock)
-          sleep 0.1
+          sock.shutdown(Socket::SHUT_WR)
+          sock.read_timeout = 1
+          sock.read unless sock.eof?
         ensure
           sock.close
         end

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

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