Class: Async::IO::SSLSocket
- Defined in:
- lib/async/io/ssl_socket.rb
Overview
Asynchronous TCP socket wrapper.
Constant Summary
Constants inherited from Generic
Class Method Summary collapse
-
.connect(socket, context, hostname = nil, &block) ⇒ Object
It’s hard to know what #to_io / #io should do.
- .wrap(socket, context) ⇒ Object
Instance Method Summary collapse
-
#accept ⇒ Object
Invokes ‘accept_nonblock` on the underlying io.
-
#connect ⇒ Object
Invokes ‘connect_nonblock` on the underlying io.
- #local_address ⇒ Object
- #remote_address ⇒ Object
Methods inherited from Generic
#nonblock, #nonblock?, #read, #wait, wrap_blocking_method, wraps, #write
Class Method Details
.connect(socket, context, hostname = nil, &block) ⇒ Object
It’s hard to know what #to_io / #io should do. So, they are omitted.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/async/io/ssl_socket.rb', line 41 def self.connect(socket, context, hostname = nil, &block) client = self.wrap(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 |
.wrap(socket, context) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/async/io/ssl_socket.rb', line 75 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) end |
Instance Method Details
#accept ⇒ Object
Invokes ‘accept_nonblock` on the underlying io. If the operation would block, the current task is paused until the operation can succeed, at which point it’s resumed and the operation is completed.
33 |
# File 'lib/async/io/ssl_socket.rb', line 33 wrap_blocking_method :accept, :accept_nonblock |
#connect ⇒ Object
Invokes ‘connect_nonblock` on the underlying io. If the operation would block, the current task is paused until the operation can succeed, at which point it’s resumed and the operation is completed.
34 |
# File 'lib/async/io/ssl_socket.rb', line 34 wrap_blocking_method :connect, :connect_nonblock |
#local_address ⇒ Object
67 68 69 |
# File 'lib/async/io/ssl_socket.rb', line 67 def local_address @io.to_io.local_address end |
#remote_address ⇒ Object
71 72 73 |
# File 'lib/async/io/ssl_socket.rb', line 71 def remote_address @io.to_io.remote_address end |