class Async::IO::SSLSocket
Asynchronous TCP socket wrapper.
Public Class Methods
connect(socket, context, hostname = nil) { |client| ... }
click to toggle source
# File lib/async/io/ssl_socket.rb, line 38 def self.connect(socket, context, hostname = nil, &block) client = self.new(socket, context) # Used for SNI: if hostname client.hostname = hostname end begin client.connect rescue # If the connection fails (e.g. certificates are invalid), the caller never sees the socket, so we close it and raise the exception up the chain. client.close raise end return client unless block_given? begin yield client ensure client.close end end
new(socket, context)
click to toggle source
Calls superclass method
# File lib/async/io/ssl_socket.rb, line 66 def initialize(socket, context) if socket.is_a?(self.class.wrapped_klass) super else io = self.class.wrapped_klass.new(socket.to_io, context) super(io, socket.reactor) # 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 @timeout = socket.timeout end end
Public Instance Methods
close_read()
click to toggle source
# File lib/async/io/ssl_socket.rb, line 95 def close_read self.shutdown(Socket::SHUT_RD) end
close_write()
click to toggle source
# File lib/async/io/ssl_socket.rb, line 91 def close_write self.shutdown(Socket::SHUT_WR) end
local_address()
click to toggle source
# File lib/async/io/ssl_socket.rb, line 83 def local_address @io.to_io.local_address end
remote_address()
click to toggle source
# File lib/async/io/ssl_socket.rb, line 87 def remote_address @io.to_io.remote_address end
shutdown(how)
click to toggle source
# File lib/async/io/ssl_socket.rb, line 99 def shutdown(how) @io.flush @io.to_io.shutdown(how) end