class Socketry::SSL::Server

SSL Server

Public Class Methods

new( hostname_or_port, port = nil, ssl_socket_class: OpenSSL::SSL::SSLSocket, ssl_params: nil, **args ) click to toggle source

Create a new SSL server

@return [Socketry::SSL::Server]

Calls superclass method Socketry::TCP::Server::new
# File lib/socketry/ssl/server.rb, line 11
def initialize(
  hostname_or_port,
  port = nil,
  ssl_socket_class: OpenSSL::SSL::SSLSocket,
  ssl_params: nil,
  **args
)
  raise TypeError, "expected Hash, got #{ssl_params.class}" if ssl_params && !ssl_params.is_a?(Hash)

  @ssl_socket_class = ssl_socket_class
  @ssl_params = ssl_params

  super(hostname_or_port, port, **args)
end

Public Instance Methods

accept(timeout: nil, **args) click to toggle source

Accept a connection to the server

Note that this method also performs an SSL handshake and will therefore block other sockets which are ready to be accepted.

Multithreaded servers should invoke this method after spawning a thread to ensure a slow/malicious connection can't cause a denial-of-service attack against the server.

@param timeout [Numeric, NilClass] (default nil, unlimited) seconds to wait before aborting the accept

@return [Socketry::SSL::Socket]

Calls superclass method Socketry::TCP::Server#accept
# File lib/socketry/ssl/server.rb, line 38
def accept(timeout: nil, **args)
  tcp_socket = super(timeout: timeout, **args)

  ssl_socket = Socketry::SSL::Socket.new(
    read_timeout:     @read_timeout,
    write_timeout:    @write_timeout,
    resolver:         @resolver,
    ssl_socket_class: @ssl_socket_class,
    ssl_params:       @ssl_params
  )

  ssl_socket.accept(tcp_socket, timeout: timeout)
end