Class: Reel::SSLServer

Inherits:
Server
  • Object
show all
Defined in:
lib/reel/ssl_server.rb

Constant Summary

Constants inherited from Server

Reel::Server::DEFAULT_BACKLOG

Instance Method Summary collapse

Methods inherited from Server

#handle_connection, #shutdown

Constructor Details

#initialize(host, port, options = {}, &callback) ⇒ SSLServer

Returns a new instance of SSLServer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/reel/ssl_server.rb', line 5

def initialize(host, port, options = {}, &callback)
  backlog = options.fetch(:backlog, DEFAULT_BACKLOG)

  # Ideally we can encapsulate this rather than making Ruby OpenSSL a
  # mandatory part of the Reel API. It would be nice to support
  # alternatives (e.g. Puma's MiniSSL)
  ssl_context      = OpenSSL::SSL::SSLContext.new
  ssl_context.cert = OpenSSL::X509::Certificate.new options.fetch(:cert)
  ssl_context.key  = OpenSSL::PKey::RSA.new options.fetch(:key)

  # We don't presently support verifying client certificates
  # TODO: support client certificates!
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE

  @tcpserver  = Celluloid::IO::TCPServer.new(host, port)
  @server     = Celluloid::IO::SSLServer.new(@tcpserver, ssl_context)

  @server.listen(backlog)
  @callback = callback

  async.run
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/reel/ssl_server.rb', line 28

def run
  loop do
    begin
      socket = @server.accept
    rescue OpenSSL::SSL::SSLError => ex
      Logger.warn "Error accepting SSLSocket: #{ex.class}: #{ex.to_s}"
      retry
    end

    async.handle_connection socket
  end
end