[前][次][番号順一覧][スレッド一覧]

ruby-changes:44787

From: shugo <ko1@a...>
Date: Mon, 21 Nov 2016 17:55:30 +0900 (JST)
Subject: [ruby-changes:44787] shugo:r56860 (trunk): Use dynamic dispatch instead of is_a?.

shugo	2016-11-21 17:55:25 +0900 (Mon, 21 Nov 2016)

  New Revision: 56860

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56860

  Log:
    Use dynamic dispatch instead of is_a?.

  Modified files:
    trunk/lib/net/ftp.rb
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 56859)
+++ lib/net/ftp.rb	(revision 56860)
@@ -362,7 +362,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L362
           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 https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L565
         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 https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1401
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1434
         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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]