Class: Async::IO::Endpoint

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/async/io/endpoint.rb

Direct Known Subclasses

AddressEndpoint, SecureEndpoint, SocketEndpoint

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification, **options) ⇒ Endpoint

Returns a new instance of Endpoint.



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

def initialize(specification, **options)
	super(specification, options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



28
29
30
# File 'lib/async/io/endpoint.rb', line 28

def options
  @options
end

#specificationObject

Returns the value of attribute specification

Returns:

  • (Object)

    the current value of specification



28
29
30
# File 'lib/async/io/endpoint.rb', line 28

def specification
  @specification
end

Class Method Details

.each(specifications, &block) ⇒ Object

Generate a list of endpoints from an array.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/async/io/endpoint.rb', line 54

def each(specifications, &block)
	return to_enum(:each, specifications) unless block_given?
	
	specifications.each do |specification|
		if specification.is_a? self
			yield specification
		elsif specification.is_a? Array
			yield self.send(*specification)
		elsif specification.is_a? String
			yield self.parse(specification)
		else
			yield self.new(specification)
		end
	end
end

.parse(string, **options) ⇒ Object



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

def parse(string, **options)
	uri = URI.parse(string)
	self.send(uri.scheme, uri.host, uri.port, **options)
end

.ssl(*args, **options) ⇒ Object



49
50
51
# File 'lib/async/io/endpoint.rb', line 49

def ssl(*args, **options)
	SecureEndpoint.new(Endpoint.tcp(*args, **options), **options)
end

.tcp(*args, **options) ⇒ Object



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

def tcp(*args, **options)
	AddressEndpoint.new(Address.tcp(*args), **options)
end

.udp(*args, **options) ⇒ Object



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

def udp(*args, **options)
	AddressEndpoint.new(Address.udp(*args), **options)
end

.unix(*args, **options) ⇒ Object



45
46
47
# File 'lib/async/io/endpoint.rb', line 45

def unix(*args, **options)
	AddressEndpoint.new(Address.unix(*args), **options)
end

Instance Method Details

#accept(&block) ⇒ Object

def bind yield specification end



101
102
103
104
105
106
107
108
# File 'lib/async/io/endpoint.rb', line 101

def accept(&block)
	backlog = self.options.fetch(:backlog, Socket::SOMAXCONN)
	
	bind do |server|
		server.listen(backlog)
		server.accept_each(&block)
	end
end

#socket_domainObject

PF_* eg PF_INET etc, normally identical to AF_* constants.



88
89
90
# File 'lib/async/io/endpoint.rb', line 88

def socket_domain
	address.afamily
end

#socket_protocolObject

IPPROTO_TCP, IPPROTO_UDP, IPPROTO_IPX, etc.



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

def socket_protocol
	address.protocol
end

#socket_typeObject

SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, etc.



83
84
85
# File 'lib/async/io/endpoint.rb', line 83

def socket_type
	address.socktype
end

#to_sockaddrObject Also known as: to_str



75
76
77
# File 'lib/async/io/endpoint.rb', line 75

def to_sockaddr
	address.to_sockaddr
end