Class: Async::IO::SecureEndpoint

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/async/io/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#accept, each, parse, ssl, tcp, try_convert, udp, unix

Constructor Details

#initialize(endpoint, **options) ⇒ SecureEndpoint

Returns a new instance of SecureEndpoint.



175
176
177
178
179
# File 'lib/async/io/endpoint.rb', line 175

def initialize(endpoint, **options)
  super(**options)
  
  @endpoint = endpoint
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



189
190
191
# File 'lib/async/io/endpoint.rb', line 189

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.



190
191
192
# File 'lib/async/io/endpoint.rb', line 190

def options
  @options
end

Instance Method Details

#bindObject



213
214
215
216
217
# File 'lib/async/io/endpoint.rb', line 213

def bind
  @endpoint.bind do |server|
    yield SSLServer.new(server, context)
  end
end

#connect(&block) ⇒ Object



219
220
221
# File 'lib/async/io/endpoint.rb', line 219

def connect(&block)
  SSLSocket.connect(@endpoint.connect, context, hostname, &block)
end

#contextObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/async/io/endpoint.rb', line 196

def context
  if context = @options[:ssl_context]
    if params = self.params
      context = context.dup
      context.set_params(params)
    end
  else
    context = ::OpenSSL::SSL::SSLContext.new
    
    if params = self.params
      context.set_params(params)
    end
  end
  
  return context
end

#eachObject



223
224
225
226
227
228
229
# File 'lib/async/io/endpoint.rb', line 223

def each
  return to_enum unless block_given?
  
  @endpoint.each do |endpoint|
    yield self.class.new(endpoint, @options)
  end
end

#hostnameObject



185
186
187
# File 'lib/async/io/endpoint.rb', line 185

def hostname
  @options.fetch(:hostname) {@endpoint.hostname}
end

#paramsObject



192
193
194
# File 'lib/async/io/endpoint.rb', line 192

def params
  @options[:ssl_params]
end

#to_sObject



181
182
183
# File 'lib/async/io/endpoint.rb', line 181

def to_s
  "\#<#{self.class} #{@endpoint}>"
end