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

Use dynamic dispatch instead of is_a?.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2016-11-21 08:55:25 +00:00
parent 4081b34d4c
commit 4c839a2cec

View file

@ -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