Class: Async::IO::Endpoint
- Inherits:
-
Struct
- Object
- Struct
- Async::IO::Endpoint
show all
- Includes:
- Comparable
- Defined in:
- lib/async/io/endpoint.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.each(specifications, &block) ⇒ Object
Generate a list of endpoints from an array.
-
.parse(string, **options) ⇒ Object
-
.ssl(*args, **options) ⇒ Object
-
.tcp(*args, **options) ⇒ Object
args: nodename, service, family, socktype, protocol, flags.
-
.udp(*args, **options) ⇒ Object
-
.unix(*args, **options) ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(specification, **options) ⇒ Endpoint
Returns a new instance of Endpoint.
80
81
82
|
# File 'lib/async/io/endpoint.rb', line 80
def initialize(specification, **options)
super(specification, options)
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options
28
29
30
|
# File 'lib/async/io/endpoint.rb', line 28
def options
@options
end
|
#specification ⇒ Object
Returns the value of attribute 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.
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/async/io/endpoint.rb', line 59
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)
elsif specification.is_a? ::BasicSocket
yield SocketEndpoint.new(specification)
elsif specification.is_a? Generic
yield Endpoint.new(specification)
else
raise ArgumentError.new("Not sure how to convert #{specification} to endpoint!")
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
54
55
56
|
# File 'lib/async/io/endpoint.rb', line 54
def ssl(*args, **options)
SecureEndpoint.new(self.tcp(*args, **options), **options)
end
|
.tcp(*args, **options) ⇒ Object
args: nodename, service, family, socktype, protocol, flags
38
39
40
41
42
|
# File 'lib/async/io/endpoint.rb', line 38
def tcp(*args, **options)
args[3] = ::Socket::SOCK_STREAM
HostEndpoint.new(args, **options)
end
|
.udp(*args, **options) ⇒ Object
44
45
46
47
48
|
# File 'lib/async/io/endpoint.rb', line 44
def udp(*args, **options)
args[3] = ::Socket::SOCK_DGRAM
HostEndpoint.new(args, **options)
end
|
.unix(*args, **options) ⇒ Object
50
51
52
|
# File 'lib/async/io/endpoint.rb', line 50
def unix(*args, **options)
AddressEndpoint.new(Address.unix(*args), **options)
end
|
Instance Method Details
#accept(&block) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/async/io/endpoint.rb', line 88
def accept(&block)
backlog = self.options.fetch(:backlog, Socket::SOMAXCONN)
bind do |server|
server.listen(backlog)
server.accept_each(&block)
end
end
|
#bind {|specification| ... } ⇒ Object
84
85
86
|
# File 'lib/async/io/endpoint.rb', line 84
def bind
yield specification
end
|
#connect {|specification| ... } ⇒ Object
97
98
99
|
# File 'lib/async/io/endpoint.rb', line 97
def connect
yield specification
end
|