Skip to Content Skip to Search

SSLServer represents a TCP/IP server socket with Secure Sockets Layer.

Methods
A
C
L
N
S
T
Included Modules

Attributes

[RW] start_immediately

When true then accept works exactly the same as TCPServer#accept

Class Public methods

new(svr, ctx)

Creates a new instance of SSLServer.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 491
def initialize(svr, ctx)
  @svr = svr
  @ctx = ctx
  unless ctx.session_id_context
    # see #6137 - session id may not exceed 32 bytes
    prng = ::Random.new($0.hash)
    session_id = prng.bytes(16).unpack1('H*')
    @ctx.session_id_context = session_id
  end
  @start_immediately = true
end

Instance Public methods

accept()

Works similar to TCPServer#accept.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 519
def accept
  # Socket#accept returns [socket, addrinfo].
  # TCPServer#accept returns a socket.
  # The following comma strips addrinfo.
  sock, = @svr.accept
  begin
    ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
    ssl.sync_close = true
    ssl.accept if @start_immediately
    ssl
  rescue Exception => ex
    if ssl
      ssl.close
    else
      sock.close
    end
    raise ex
  end
end

close()

See IO#close for details.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 540
def close
  @svr.close
end

listen(backlog=Socket::SOMAXCONN)

See TCPServer#listen for details.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 509
def listen(backlog=Socket::SOMAXCONN)
  @svr.listen(backlog)
end

shutdown(how=Socket::SHUT_RDWR)

See BasicSocket#shutdown for details.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 514
def shutdown(how=Socket::SHUT_RDWR)
  @svr.shutdown(how)
end

to_io()

Returns the TCPServer passed to the SSLServer when initialized.

# File ruby/ext/openssl/lib/openssl/ssl.rb, line 504
def to_io
  @svr
end