Class: Socketry::SSL::Server
- Inherits:
-
TCP::Server
- Object
- TCP::Server
- Socketry::SSL::Server
- Defined in:
- lib/socketry/ssl/server.rb
Overview
SSL Server
Constant Summary
Constants included from Timeout
Timeout::DEFAULT_TIMEOUTS, Timeout::DEFAULT_TIMER
Instance Attribute Summary
Attributes inherited from TCP::Server
#read_timeout, #resolver, #socket_class, #write_timeout
Instance Method Summary collapse
-
#accept(timeout: nil, **args) ⇒ Socketry::SSL::Socket
Accept a connection to the server.
-
#initialize(hostname_or_port, port = nil, ssl_socket_class: OpenSSL::SSL::SSLSocket, ssl_params: nil, **args) ⇒ Socketry::SSL::Server
constructor
Create a new SSL server.
Methods inherited from TCP::Server
Methods included from Timeout
#clear_timeout, #lifetime, #set_timeout, #start_timer, #time_remaining
Constructor Details
#initialize(hostname_or_port, port = nil, ssl_socket_class: OpenSSL::SSL::SSLSocket, ssl_params: nil, **args) ⇒ Socketry::SSL::Server
Create a new SSL server
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
Instance Method Details
#accept(timeout: nil, **args) ⇒ Socketry::SSL::Socket
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |