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

* lib/net/ftp.rb (Net::FTP#transfercmd): rescue shutdown.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2012-05-21 02:27:07 +00:00
parent d795f2d1a8
commit 52f0c6780e
3 changed files with 30 additions and 12 deletions

View file

@ -1,3 +1,7 @@
Mon May 21 11:26:17 2012 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/ftp.rb (Net::FTP#transfercmd): rescue shutdown.
Sun May 20 23:00:11 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): reopen $stdout to NULL, since setting

View file

@ -433,7 +433,7 @@ module Net
end
conn = BufferedSocket.new(sock.accept)
conn.read_timeout = @read_timeout
sock.shutdown(Socket::SHUT_WR)
sock.shutdown(Socket::SHUT_WR) rescue nil
sock.read rescue nil
sock.close
end
@ -483,16 +483,19 @@ module Net
def retrbinary(cmd, blocksize, rest_offset = nil) # :yield: data
synchronize do
with_binary(true) do
conn = transfercmd(cmd, rest_offset)
loop do
data = conn.read(blocksize)
break if data == nil
yield(data)
begin
conn = transfercmd(cmd, rest_offset)
loop do
data = conn.read(blocksize)
break if data == nil
yield(data)
end
conn.shutdown(Socket::SHUT_WR)
conn.read_timeout = 1
conn.read
ensure
conn.close
end
conn.shutdown(Socket::SHUT_WR)
conn.read_timeout = 1
conn.read
conn.close
voidresp
end
end

View file

@ -6,6 +6,16 @@ require "stringio"
class FTPTest < Test::Unit::TestCase
SERVER_ADDR = "127.0.0.1"
def setup
@thread = nil
end
def teardown
if @thread
@thread.join
end
end
def test_not_connected
ftp = Net::FTP.new
assert_raise(Net::FTPConnectionError) do
@ -272,7 +282,8 @@ class FTPTest < Test::Unit::TestCase
conn.print(l, "\r\n")
end
conn.shutdown(Socket::SHUT_WR)
conn.read
conn.read_timeout = 1
conn.read unless conn.eof?
conn.close
sock.print("226 Directory send OK.\r\n")
}
@ -586,7 +597,7 @@ class FTPTest < Test::Unit::TestCase
def create_ftp_server(sleep_time = nil)
server = TCPServer.new(SERVER_ADDR, 0)
Thread.start do
@thread = Thread.start do
begin
if sleep_time
sleep(sleep_time)