1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2017-05-12 09:39:23 +00:00
parent 952fa45645
commit 5bf395f4cb

View file

@ -227,11 +227,6 @@ module Net
# 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
# 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
@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
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