aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-21 08:55:25 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-21 08:55:25 +0000
commite7dfcb0293ddb5046a7efd0915eaf51db53e69d9 (patch)
tree6a10d1c796573163f4693aad203d238c9f193fdb /lib
parenta28007ef9dae37cf1b36ae5d1c594a88d57399aa (diff)
downloadruby-e7dfcb0293ddb5046a7efd0915eaf51db53e69d9.tar.gz
Use dynamic dispatch instead of is_a?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/ftp.rb30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 56f73eb475..278dd51024 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -362,7 +362,7 @@ module Net
begin
voidcmd("AUTH TLS")
ssl_sock = start_tls_session(@bare_sock)
- @sock = BufferedSocket.new(ssl_sock, read_timeout: @read_timeout)
+ @sock = BufferedSSLSocket.new(ssl_sock, read_timeout: @read_timeout)
if @private_data_connection
voidcmd("PBSZ 0")
voidcmd("PROT P")
@@ -565,9 +565,11 @@ module Net
end
end
if @private_data_connection
- conn = start_tls_session(conn)
+ return BufferedSSLSocket.new(start_tls_session(conn),
+ read_timeout: @read_timeout)
+ else
+ return BufferedSocket.new(conn, read_timeout: @read_timeout)
end
- return BufferedSocket.new(conn, read_timeout: @read_timeout)
end
private :transfercmd
@@ -1399,22 +1401,12 @@ module Net
end
class BufferedSocket < BufferedIO
- [:local_address, :remote_address, :addr, :peeraddr, :send].each do |method|
+ [:local_address, :remote_address, :addr, :peeraddr, :send, :shutdown].each do |method|
define_method(method) { |*args|
@io.__send__(method, *args)
}
end
- def shutdown(*args)
- if defined?(OpenSSL::SSL::SSLSocket) &&
- @io.is_a?(OpenSSL::SSL::SSLSocket)
- # If @io is an SSLSocket, SSL_shutdown() will be called from
- # SSLSocket#close, so shutdown(2) should not be called.
- else
- @io.shutdown(*args)
- end
- end
-
def read(len = nil)
if len
s = super(len, String.new, true)
@@ -1442,6 +1434,16 @@ module Net
return line
end
end
+
+ if defined?(OpenSSL::SSL::SSLSocket)
+ class BufferedSSLSocket < BufferedSocket
+ def shutdown(*args)
+ # SSL_shutdown() will be called from SSLSocket#close, and
+ # SSL_shutdonw() will send the "close notify" alert to the peer,
+ # so shutdown(2) should not be called.
+ end
+ end
+ end
# :startdoc:
end
end