lib/async/io/ssl_socket.rb in async-io-1.16.1 vs lib/async/io/ssl_socket.rb in async-io-1.16.2

- old
+ new

@@ -35,11 +35,11 @@ alias syswrite write alias sysread read def self.connect(socket, context, hostname = nil, &block) - client = self.wrap(socket, context) + client = self.new(socket, context) # Used for SNI: if hostname client.hostname = hostname end @@ -70,20 +70,24 @@ @io.to_io.remote_address end include Peer - def self.wrap(socket, context) - io = @wrapped_klass.new(socket.to_io, context) - - # We detach the socket from the reactor, otherwise it's possible to add the file descriptor to the selector twice, which is bad. - socket.reactor = nil - - # This ensures that when the internal IO is closed, it also closes the internal socket: - io.sync_close = true - - return self.new(io, socket.reactor) + def initialize(socket, context) + if socket.is_a?(self.class.wrapped_klass) + super + else + io = self.class.wrapped_klass.new(socket.to_io, context) + + # We detach the socket from the reactor, otherwise it's possible to add the file descriptor to the selector twice, which is bad. + socket.reactor = nil + + # This ensures that when the internal IO is closed, it also closes the internal socket: + io.sync_close = true + + super(io, socket.reactor) + end end end # We reimplement this from scratch because the native implementation doesn't expose the underlying server/context that we need to implement non-blocking accept. class SSLServer @@ -108,10 +112,10 @@ end def accept(task: Task.current) peer, address = @server.accept - wrapper = SSLSocket.wrap(peer, @context) + wrapper = SSLSocket.new(peer, @context) return wrapper, address unless block_given? task.async do task.annotate "accepting secure connection #{address.inspect}"