Class: Async::IO::SSLServer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Server
Defined in:
lib/async/io/ssl_socket.rb

Overview

We reimplement this from scratch because the native implementation doesn’t expose the underlying server/context that we need to implement non-blocking accept.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Server

#accept_each

Constructor Details

#initialize(server, context) ⇒ SSLServer

Returns a new instance of SSLServer.



92
93
94
95
# File 'lib/async/io/ssl_socket.rb', line 92

def initialize(server, context)
  @server = server
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



100
101
102
# File 'lib/async/io/ssl_socket.rb', line 100

def context
  @context
end

#serverObject (readonly)

Returns the value of attribute server.



99
100
101
# File 'lib/async/io/ssl_socket.rb', line 99

def server
  @server
end

Instance Method Details

#accept(task: Task.current) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/async/io/ssl_socket.rb', line 106

def accept(task: Task.current)
  peer, address = @server.accept
  
  wrapper = SSLSocket.wrap(peer, @context)
  
  return wrapper, address unless block_given?
  
  task.async do
    task.annotate "accepting secure connection #{address}"
    
    begin
      # You want to do this in a nested async task or you might suffer from head-of-line blocking.
      wrapper.accept
      
      yield wrapper, address
    rescue SSLError
      Async.logger.error($!.class) {$!}
    ensure
      wrapper.close
    end
  end
end

#listen(*args) ⇒ Object



102
103
104
# File 'lib/async/io/ssl_socket.rb', line 102

def listen(*args)
  @server.listen(*args)
end