From e7dfcb0293ddb5046a7efd0915eaf51db53e69d9 Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 21 Nov 2016 08:55:25 +0000 Subject: Use dynamic dispatch instead of is_a?. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/ftp.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'lib/net/ftp.rb') 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 -- cgit v1.2.3