Class: OpenSSL::SSL::SSLServer
- Inherits:
-
Object
- Object
- OpenSSL::SSL::SSLServer
- Includes:
- SocketForwarder
- Defined in:
- lib/openssl/ssl.rb
Overview
SSLServer represents a TCP/IP server socket with Secure Sockets Layer.
Instance Attribute Summary collapse
-
#start_immediately ⇒ Object
When true then #accept works exactly the same as TCPServer#accept.
Instance Method Summary collapse
-
#accept ⇒ Object
Works similar to TCPServer#accept.
-
#close ⇒ Object
See IO#close for details.
-
#initialize(svr, ctx) ⇒ SSLServer
constructor
Creates a new instance of SSLServer.
-
#listen(backlog = Socket::SOMAXCONN) ⇒ Object
See TCPServer#listen for details.
-
#shutdown(how = Socket::SHUT_RDWR) ⇒ Object
See BasicSocket#shutdown for details.
-
#to_io ⇒ Object
Returns the TCPServer passed to the SSLServer when initialized.
Methods included from SocketForwarder
#addr, #close_on_exec=, #close_on_exec?, #closed?, #do_not_reverse_lookup=, #fcntl, #fileno, #getsockopt, #local_address, #peeraddr, #remote_address, #setsockopt, #timeout, #timeout=, #wait, #wait_readable, #wait_writable
Constructor Details
#initialize(svr, ctx) ⇒ SSLServer
Creates a new instance of SSLServer.
-
srv is an instance of TCPServer.
-
ctx is an instance of OpenSSL::SSL::SSLContext.
554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/openssl/ssl.rb', line 554 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 Attribute Details
#start_immediately ⇒ Object
When true then #accept works exactly the same as TCPServer#accept
549 550 551 |
# File 'lib/openssl/ssl.rb', line 549 def start_immediately @start_immediately end |
Instance Method Details
#accept ⇒ Object
Works similar to TCPServer#accept.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/openssl/ssl.rb', line 582 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 ⇒ Object
See IO#close for details.
603 604 605 |
# File 'lib/openssl/ssl.rb', line 603 def close @svr.close end |
#listen(backlog = Socket::SOMAXCONN) ⇒ Object
See TCPServer#listen for details.
572 573 574 |
# File 'lib/openssl/ssl.rb', line 572 def listen(backlog=Socket::SOMAXCONN) @svr.listen(backlog) end |
#shutdown(how = Socket::SHUT_RDWR) ⇒ Object
See BasicSocket#shutdown for details.
577 578 579 |
# File 'lib/openssl/ssl.rb', line 577 def shutdown(how=Socket::SHUT_RDWR) @svr.shutdown(how) end |
#to_io ⇒ Object
Returns the TCPServer passed to the SSLServer when initialized.
567 568 569 |
# File 'lib/openssl/ssl.rb', line 567 def to_io @svr end |