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

ruby-changes:44788

From: shugo <ko1@a...>
Date: Mon, 21 Nov 2016 19:38:36 +0900 (JST)
Subject: [ruby-changes:44788] shugo:r56861 (trunk): Add new options open_timeout and read_timeout to Net::FTP.new.

shugo	2016-11-21 19:38:31 +0900 (Mon, 21 Nov 2016)

  New Revision: 56861

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

  Log:
    Add new options open_timeout and read_timeout to Net::FTP.new.

  Modified files:
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 56860)
+++ lib/net/ftp.rb	(revision 56861)
@@ -190,6 +190,10 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L190
     # account::   Account information for ACCT.
     # passive::   When +true+, the connection is in passive mode. Default:
     #             +true+.
+    # open_timeout::  Number of seconds to wait for the connection to open.
+    #                 See Net::FTP#open_timeout for details.  Default: +nil+.
+    # read_timeout::  Number of seconds to wait for one block to be read.
+    #                 See Net::FTP#read_timeout for details.  Default: +60+.
     # debug_mode::  When +true+, all traffic to and from the server is
     #               written to +$stdout+.  Default: +false+.
     #
@@ -242,8 +246,8 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L246
       @resume = false
       @bare_sock = @sock = NullSocket.new
       @logged_in = false
-      @open_timeout = nil
-      @read_timeout = 60
+      @open_timeout = options[:open_timeout]
+      @read_timeout = options[:read_timeout] || 60
       if host
         if options[:port]
           connect(host, options[:port] || FTP_PORT)
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 56860)
+++ test/net/ftp/test_ftp.rb	(revision 56861)
@@ -278,6 +278,16 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L278
     end
   end
 
+  def test_s_new_timeout_options
+    ftp = Net::FTP.new
+    assert_equal(nil, ftp.open_timeout)
+    assert_equal(60, ftp.read_timeout)
+
+    ftp = Net::FTP.new(nil, open_timeout: 123, read_timeout: 234)
+    assert_equal(123, ftp.open_timeout)
+    assert_equal(234, ftp.read_timeout)
+  end
+
   # TODO: How can we test open_timeout?  sleep before accept cannot delay
   # connections.
   def _test_open_timeout_exceeded

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

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