class IO::Endpoint::SSLEndpoint
def address
def address @endpoint.address end
def bind(*arguments, **options, &block)
-
(Socket)- the connected socket
Other tags:
- Yield: - the socket which is being connected
def bind(*arguments, **options, &block) if block_given? @endpoint.bind(*arguments, **options) do |server| yield self.make_server(server) end else @endpoint.bind(*arguments, **options).map do |server| self.make_server(server) end end end
def build_context(context = ::OpenSSL::SSL::SSLContext.new)
def build_context(context = ::OpenSSL::SSL::SSLContext.new) if params = self.params context.set_params(params) end # context.setup # context.freeze return context end
def connect(&block)
-
(Socket)- the connected socket
Other tags:
- Yield: - the socket which is being connected
def connect(&block) socket = self.make_socket(@endpoint.connect) if hostname = self.hostname socket.hostname = hostname end begin socket.connect rescue socket.close raise end return socket unless block_given? begin yield socket ensure socket.close end end
def context
def context @context ||= build_context end
def each
def each return to_enum unless block_given? @endpoint.each do |endpoint| yield self.class.new(endpoint, **@options) end end
def hostname
def hostname @options[:hostname] || @endpoint.hostname end
def initialize(endpoint, **options)
def initialize(endpoint, **options) super(**options) @endpoint = endpoint if ssl_context = options[:ssl_context] @context = build_context(ssl_context) else @context = nil end end
def inspect
def inspect "\#<#{self.class} endpoint=#{@endpoint.inspect}>" end
def make_server(io)
def make_server(io) ::OpenSSL::SSL::SSLServer.new(io, self.context).tap do |server| server.start_immediately = false end end
def make_socket(io)
def make_socket(io) ::OpenSSL::SSL::SSLSocket.new(io, self.context).tap do |socket| # We consider the underlying IO is owned by the SSL socket: socket.sync_close = true end end
def params
def params @options[:ssl_params] end
def to_s
def to_s "ssl:#{@endpoint}" end