Class: Async::IO::SSLEndpoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

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

Constructor Details

#initialize(endpoint, **options) ⇒ SSLEndpoint

Returns a new instance of SSLEndpoint.



27
28
29
30
31
# File 'lib/async/io/ssl_endpoint.rb', line 27

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

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



41
42
43
# File 'lib/async/io/ssl_endpoint.rb', line 41

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.



42
43
44
# File 'lib/async/io/ssl_endpoint.rb', line 42

def options
  @options
end

Instance Method Details

#bindObject



65
66
67
68
69
# File 'lib/async/io/ssl_endpoint.rb', line 65

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

#connect(&block) ⇒ Object



71
72
73
# File 'lib/async/io/ssl_endpoint.rb', line 71

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

#contextObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/async/io/ssl_endpoint.rb', line 48

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



75
76
77
78
79
80
81
# File 'lib/async/io/ssl_endpoint.rb', line 75

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

#hostnameObject



37
38
39
# File 'lib/async/io/ssl_endpoint.rb', line 37

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

#paramsObject



44
45
46
# File 'lib/async/io/ssl_endpoint.rb', line 44

def params
	@options[:ssl_params]
end

#to_sObject



33
34
35
# File 'lib/async/io/ssl_endpoint.rb', line 33

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