diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-03 19:24:30 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-03 19:24:30 +0000 |
commit | bc2ece6cf8e9c96f94ba7335cef886b7c5c0f833 (patch) | |
tree | 022f60f9af8b0bf054d5b43798e0757ec7366103 /lib/net | |
parent | d7655cc292c431264723547bbf8ea946517ca92c (diff) | |
download | ruby-bc2ece6cf8e9c96f94ba7335cef886b7c5c0f833.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r-- | lib/net/ftp.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 62730a3f5b..9a11515b2b 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -932,7 +932,12 @@ module Net # 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 @@ module Net 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 @@ module Net 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 |