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.



150
151
152
153
# File 'lib/async/io/endpoint.rb', line 150

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

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



155
156
157
# File 'lib/async/io/endpoint.rb', line 155

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.



156
157
158
# File 'lib/async/io/endpoint.rb', line 156

def options
  @options
end

Instance Method Details

#bindObject



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

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

#connect(&block) ⇒ Object



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

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

#contextObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/async/io/endpoint.rb', line 166

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



193
194
195
196
197
198
199
# File 'lib/async/io/endpoint.rb', line 193

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

#hostnameObject



158
159
160
# File 'lib/async/io/endpoint.rb', line 158

def hostname
  @options[:hostname]
end

#paramsObject



162
163
164
# File 'lib/async/io/endpoint.rb', line 162

def params
  @options[:ssl_params]
end