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

ruby-changes:46565

From: shugo <ko1@a...>
Date: Fri, 12 May 2017 18:39:29 +0900 (JST)
Subject: [ruby-changes:46565] shugo:r58680 (trunk): net/imap: Revert read_tiemout in r58549.

shugo	2017-05-12 18:39:23 +0900 (Fri, 12 May 2017)

  New Revision: 58680

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

  Log:
    net/imap: Revert read_tiemout in r58549.
    
    get_response is called in a receiver thread, so there may be no pending
    commands when get_response is called.

  Modified files:
    trunk/lib/net/imap.rb
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 58679)
+++ lib/net/imap.rb	(revision 58680)
@@ -227,11 +227,6 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L227
     # it raises a Net::OpenTimeout exception. The default value is 30 seconds.
     attr_reader :open_timeout
 
-    # Seconds to wait until reading one block (by one read(1) call).
-    # If the IMAP object cannot complete a read() within this time,
-    # it raises a Net::ReadTimeout exception. The default value is 60 seconds.
-    attr_reader :read_timeout
-
     # The thread to receive exceptions.
     attr_accessor :client_thread
 
@@ -1061,7 +1056,6 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1056
     #         If options[:ssl] is a hash, it's passed to
     #         OpenSSL::SSL::SSLContext#set_params as parameters.
     # open_timeout:: Seconds to wait until a connection is opened
-    # read_timeout:: Seconds to wait until reading one block
     #
     # The most common errors are:
     #
@@ -1091,7 +1085,6 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1085
       @tag_prefix = "RUBY"
       @tagno = 0
       @open_timeout = options[:open_timeout] || 30
-      @read_timeout = options[:read_timeout] || 60
       @parser = ResponseParser.new
       @sock = tcp_socket(@host, @port)
       begin
@@ -1222,35 +1215,14 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1215
       end
     end
 
-    def get_response_data(length, terminator = nil)
-      str = nil
-      buff = String.new
-      while true
-        str = @sock.read_nonblock(length, :exception => false)
-        case str
-        when :wait_readable
-          @sock.to_io.wait_readable(@read_timeout) or
-            raise Net::ReadTimeout, "#{@host}:#{@port} read timeout (exceeds #{@read_timeout} seconds)"
-        when nil
-          break
-        else
-          buff.concat(str)
-          if terminator ? buff.include?(terminator) : (buff.length >= length)
-            break
-          end
-        end
-      end
-      buff
-    end
-
     def get_response
       buff = String.new
       while true
-        s = get_response_data(1, CRLF)
-        break if s.length == 0
+        s = @sock.gets(CRLF)
+        break unless s
         buff.concat(s)
         if /\{(\d+)\}\r\n/n =~ s
-          s = get_response_data($1.to_i)
+          s = @sock.read($1.to_i)
           buff.concat(s)
         else
           break

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

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