Class: Async::IO::Endpoint
- Inherits:
-
Object
- Object
- Async::IO::Endpoint
show all
- Defined in:
- lib/async/io/endpoint.rb,
lib/async/io/ssl_endpoint.rb,
lib/async/io/endpoint/each.rb,
lib/async/io/host_endpoint.rb,
lib/async/io/socket_endpoint.rb,
lib/async/io/address_endpoint.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.each(specifications, &block) ⇒ Object
Generate a list of endpoint from an array.
-
.parse(string, **options) ⇒ Object
-
.socket(socket, **options) ⇒ Object
-
.ssl(*args, **options) ⇒ Object
-
.tcp(*args, **options) ⇒ Object
args: nodename, service, family, socktype, protocol, flags.
-
.try_convert(specification) ⇒ Object
-
.udp(*args, **options) ⇒ Object
-
.unix(*args, **options) ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(**options) ⇒ Endpoint
Returns a new instance of Endpoint.
29
30
31
|
# File 'lib/async/io/endpoint.rb', line 29
def initialize(**options)
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
33
34
35
|
# File 'lib/async/io/endpoint.rb', line 33
def options
@options
end
|
Class Method Details
.each(specifications, &block) ⇒ Object
Generate a list of endpoint from an array.
45
46
47
48
49
50
51
|
# File 'lib/async/io/endpoint/each.rb', line 45
def self.each(specifications, &block)
return to_enum(:each, specifications) unless block_given?
specifications.each do |specification|
yield try_convert(specification)
end
end
|
.parse(string, **options) ⇒ Object
53
54
55
56
57
|
# File 'lib/async/io/endpoint.rb', line 53
def self.parse(string, **options)
uri = URI.parse(string)
self.send(uri.scheme, uri.host, uri.port, **options)
end
|
.socket(socket, **options) ⇒ Object
66
67
68
|
# File 'lib/async/io/socket_endpoint.rb', line 66
def self.socket(socket, **options)
SocketEndpoint.new(socket, **options)
end
|
.ssl(*args, **options) ⇒ Object
88
89
90
|
# File 'lib/async/io/ssl_endpoint.rb', line 88
def self.ssl(*args, **options)
SSLEndpoint.new(self.tcp(*args, **options), **options)
end
|
.tcp(*args, **options) ⇒ Object
args: nodename, service, family, socktype, protocol, flags
71
72
73
74
75
|
# File 'lib/async/io/host_endpoint.rb', line 71
def self.tcp(*args, **options)
args[3] = ::Socket::SOCK_STREAM
HostEndpoint.new(args, **options)
end
|
.try_convert(specification) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/async/io/endpoint/each.rb', line 28
def self.try_convert(specification)
if specification.is_a? self
specification
elsif specification.is_a? Array
self.send(*specification)
elsif specification.is_a? String
self.parse(specification)
elsif specification.is_a? ::BasicSocket
self.socket(specification)
elsif specification.is_a? Generic
self.new(specification)
else
raise ArgumentError.new("Not sure how to convert #{specification} to endpoint!")
end
end
|
.udp(*args, **options) ⇒ Object
77
78
79
80
81
|
# File 'lib/async/io/host_endpoint.rb', line 77
def self.udp(*args, **options)
args[3] = ::Socket::SOCK_DGRAM
HostEndpoint.new(args, **options)
end
|
.unix(*args, **options) ⇒ Object
51
52
53
|
# File 'lib/async/io/address_endpoint.rb', line 51
def self.unix(*args, **options)
AddressEndpoint.new(Address.unix(*args), **options)
end
|
Instance Method Details
#accept(backlog = Socket::SOMAXCONN, &block) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/async/io/endpoint.rb', line 45
def accept(backlog = Socket::SOMAXCONN, &block)
bind do |server|
server.listen(backlog)
server.accept_each(&block)
end
end
|
#each {|_self| ... } ⇒ Object
39
40
41
42
43
|
# File 'lib/async/io/endpoint.rb', line 39
def each
return to_enum unless block_given?
yield self
end
|
#hostname ⇒ Object
35
36
37
|
# File 'lib/async/io/endpoint.rb', line 35
def hostname
@options[:hostname]
end
|