Class: Async::IO::Endpoint
- Inherits:
-
Struct
- Object
- Struct
- Async::IO::Endpoint
- Includes:
- Comparable
- Defined in:
- lib/async/io/endpoint.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#specification ⇒ Object
Returns the value of attribute specification.
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
- .udp(*args, **options) ⇒ Object
- .unix(*args, **options) ⇒ Object
Instance Method Summary collapse
-
#accept(&block) ⇒ Object
def bind yield specification end.
-
#initialize(specification, **options) ⇒ Endpoint
constructor
A new instance of Endpoint.
-
#socket_domain ⇒ Object
PF_* eg PF_INET etc, normally identical to AF_* constants.
-
#socket_protocol ⇒ Object
IPPROTO_TCP, IPPROTO_UDP, IPPROTO_IPX, etc.
-
#socket_type ⇒ Object
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, etc.
- #to_sockaddr ⇒ Object (also: #to_str)
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, **) super(specification, ) 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 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.
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, **) uri = URI.parse(string) self.send(uri.scheme, uri.host, uri.port, **) end |
.ssl(*args, **options) ⇒ Object
49 50 51 |
# File 'lib/async/io/endpoint.rb', line 49 def ssl(*args, **) SecureEndpoint.new(Endpoint.tcp(*args, **), **) end |
.tcp(*args, **options) ⇒ Object
37 38 39 |
# File 'lib/async/io/endpoint.rb', line 37 def tcp(*args, **) AddressEndpoint.new(Address.tcp(*args), **) end |
.udp(*args, **options) ⇒ Object
41 42 43 |
# File 'lib/async/io/endpoint.rb', line 41 def udp(*args, **) AddressEndpoint.new(Address.udp(*args), **) end |
.unix(*args, **options) ⇒ Object
45 46 47 |
# File 'lib/async/io/endpoint.rb', line 45 def unix(*args, **) AddressEndpoint.new(Address.unix(*args), **) 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..fetch(:backlog, Socket::SOMAXCONN) bind do |server| server.listen(backlog) server.accept_each(&block) end end |
#socket_domain ⇒ Object
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_protocol ⇒ Object
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_type ⇒ Object
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_sockaddr ⇒ Object Also known as: to_str
75 76 77 |
# File 'lib/async/io/endpoint.rb', line 75 def to_sockaddr address.to_sockaddr end |