Class: Async::IO::Endpoint
- Inherits:
-
Struct
- Object
- Struct
- Async::IO::Endpoint
- Includes:
- Comparable, Socket::Constants
- Defined in:
- lib/async/io/endpoint.rb
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
- .parse(string, **options) ⇒ Object
- .tcp(*args, **options) ⇒ Object
- .udp(*args, **options) ⇒ Object
- .unix(*args, **options) ⇒ Object
Instance Method Summary collapse
- #accept(&block) ⇒ Object
- #address ⇒ Object
- #bind(&block) ⇒ Object
- #connect(&block) ⇒ Object
-
#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.
63 64 65 |
# File 'lib/async/io/endpoint.rb', line 63 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 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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/async/io/endpoint.rb', line 50 def each(specifications, &block) specifications.each do |specification| if specification.is_a? self yield specification elsif specification.is_a? Array yield self.send(*specification) else yield self.new(specification) end end end |
.parse(string, **options) ⇒ Object
33 34 35 36 |
# File 'lib/async/io/endpoint.rb', line 33 def parse(string, **) uri = URI.parse(string) self.send(uri.scheme, uri.host, uri.port, **) end |
.tcp(*args, **options) ⇒ Object
38 39 40 |
# File 'lib/async/io/endpoint.rb', line 38 def tcp(*args, **) self.new(Address.tcp(*args), **) end |
.udp(*args, **options) ⇒ Object
42 43 44 |
# File 'lib/async/io/endpoint.rb', line 42 def udp(*args, **) self.new(Address.udp(*args), **) end |
.unix(*args, **options) ⇒ Object
46 47 48 |
# File 'lib/async/io/endpoint.rb', line 46 def unix(*args, **) self.new(Address.unix(*args), **) end |
Instance Method Details
#accept(&block) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/async/io/endpoint.rb', line 113 def accept(&block) backlog = self..fetch(:backlog, SOMAXCONN) bind do |socket| socket.listen(backlog) socket.accept_each(&block) end end |
#address ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/async/io/endpoint.rb', line 74 def address @address ||= case specification when Addrinfo specification when ::BasicSocket, BasicSocket specification.local_address else raise ArgumentError, "Not sure how to convert #{specification} into address!" end end |
#bind(&block) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/async/io/endpoint.rb', line 100 def bind(&block) case specification when Addrinfo Socket.bind(specification, **, &block) when ::BasicSocket yield Socket.new(specification) when BasicSocket yield specification else raise ArgumentError, "Not sure how to bind to #{specification}!" end end |
#connect(&block) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/async/io/endpoint.rb', line 122 def connect(&block) case specification when Addrinfo Socket.connect(specification, &block) when ::BasicSocket yield Async::IO.try_convert(specification) when BasicSocket yield specification else raise ArgumentError, "Not sure how to connect to #{specification}!" end end |
#socket_domain ⇒ Object
PF_* eg PF_INET etc, normally identical to AF_* constants.
91 92 93 |
# File 'lib/async/io/endpoint.rb', line 91 def socket_domain address.afamily end |
#socket_protocol ⇒ Object
IPPROTO_TCP, IPPROTO_UDP, IPPROTO_IPX, etc.
96 97 98 |
# File 'lib/async/io/endpoint.rb', line 96 def socket_protocol address.protocol end |
#socket_type ⇒ Object
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, etc.
86 87 88 |
# File 'lib/async/io/endpoint.rb', line 86 def socket_type address.socktype end |
#to_sockaddr ⇒ Object Also known as: to_str
67 68 69 |
# File 'lib/async/io/endpoint.rb', line 67 def to_sockaddr address.to_sockaddr end |