Class: OpenSSL::SSL::SSLServer (Ruby 2.3.2)
Description: Class : OpenSSL::SSL::SSLServer - Ruby 2.3.2

- Home
- Core 2.3.2
- Std-lib 2.3.2
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- openssl/lib/openssl/ssl.rb

### Parent

Object

### Methods

- ::new
- #accept
- #close
- #listen
- #shutdown
- #to_io

### Included Modules

- OpenSSL::SSL::SocketForwarder

### Class/Module Index

Quicksearch

- Integer
- OpenSSL::ASN1
- OpenSSL::ASN1::ASN1Data
- OpenSSL::ASN1::ASN1Error
- OpenSSL::ASN1::Constructive
- OpenSSL::ASN1::ObjectId
- OpenSSL::ASN1::Primitive
- OpenSSL::BN
- OpenSSL::BNError
- OpenSSL::Buffering
- OpenSSL::Cipher
- OpenSSL::Cipher::Cipher
- OpenSSL::Cipher::CipherError
- OpenSSL::Config
- OpenSSL::ConfigError
- OpenSSL::Digest
- OpenSSL::Digest::DigestError
- OpenSSL::Engine
- OpenSSL::Engine::EngineError
- OpenSSL::ExtConfig
- OpenSSL::HMAC
- OpenSSL::HMACError
- OpenSSL::Netscape
- OpenSSL::Netscape::SPKI
- OpenSSL::Netscape::SPKIError
- OpenSSL::OCSP
- OpenSSL::OCSP::BasicResponse
- OpenSSL::OCSP::CertificateId
- OpenSSL::OCSP::OCSPError
- OpenSSL::OCSP::Request
- OpenSSL::OCSP::Response
- OpenSSL::OpenSSLError
- OpenSSL::PKCS12
- OpenSSL::PKCS12::PKCS12Error
- OpenSSL::PKCS5
- OpenSSL::PKCS5::PKCS5Error
- OpenSSL::PKCS7
- OpenSSL::PKCS7::PKCS7Error
- OpenSSL::PKCS7::RecipientInfo
- OpenSSL::PKCS7::SignerInfo
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DHError
- OpenSSL::PKey::DSA
- OpenSSL::PKey::DSAError
- OpenSSL::PKey::EC
- OpenSSL::PKey::EC::Group
- OpenSSL::PKey::EC::Group::Error
- OpenSSL::PKey::EC::Point
- OpenSSL::PKey::EC::Point::Error
- OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::PKeyError
- OpenSSL::PKey::RSA
- OpenSSL::PKey::RSAError
- OpenSSL::Random
- OpenSSL::Random::RandomError
- OpenSSL::SSL
- OpenSSL::SSL::SSLContext
- OpenSSL::SSL::SSLContext::ExtConfig
- OpenSSL::SSL::SSLError
- OpenSSL::SSL::SSLErrorWaitReadable
- OpenSSL::SSL::SSLErrorWaitWritable
- OpenSSL::SSL::SSLServer
- OpenSSL::SSL::SSLSocket
- OpenSSL::SSL::SSLSocket::ExtConfig
- OpenSSL::SSL::Session
- OpenSSL::SSL::Session::SessionError
- OpenSSL::SSL::SocketForwarder
- OpenSSL::X509
- OpenSSL::X509::Attribute
- OpenSSL::X509::AttributeError
- OpenSSL::X509::CRL
- OpenSSL::X509::CRLError
- OpenSSL::X509::Certificate
- OpenSSL::X509::CertificateError
- OpenSSL::X509::Extension
- OpenSSL::X509::ExtensionError
- OpenSSL::X509::ExtensionFactory
- OpenSSL::X509::Name
- OpenSSL::X509::Name::RFC2253DN
- OpenSSL::X509::NameError
- OpenSSL::X509::Request
- OpenSSL::X509::RequestError
- OpenSSL::X509::Revoked
- OpenSSL::X509::RevokedError
- OpenSSL::X509::Store
- OpenSSL::X509::StoreContext
- OpenSSL::X509::StoreError
- unknown

No matching classes.

# OpenSSL::SSL::SSLServer

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

### Attributes

start_immediately[RW]

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

### Public Class Methods

new(svr, ctx) click to toggle source

Creates a new instance of SSLServer.

- `srv` is an instance of TCPServer.

- `ctx` is an instance of OpenSSL::SSL::SSLContext.

                   # File openssl/lib/openssl/ssl.rb, line 367
    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).unpack('H*')[0]
        @ctx.session_id_context = session_id
      end
      @start_immediately = true
    end

### Public Instance Methods

accept() click to toggle source

Works similar to TCPServer#accept.

                   # File openssl/lib/openssl/ssl.rb, line 395
    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() click to toggle source

See IO#close for details.

                   # File openssl/lib/openssl/ssl.rb, line 416
    def close
      @svr.close
    end

listen(backlog=5) click to toggle source

See TCPServer#listen for details.

                   # File openssl/lib/openssl/ssl.rb, line 385
    def listen(backlog=5)
      @svr.listen(backlog)
    end

shutdown(how=Socket::SHUT_RDWR) click to toggle source

See BasicSocket#shutdown for details.

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

to_io() click to toggle source

Returns the TCPServer passed to the SSLServer when initialized.

                   # File openssl/lib/openssl/ssl.rb, line 380
    def to_io
      @svr
    end