Class: Async::IO::Address
- Inherits:
-
Struct
- Object
- Struct
- Async::IO::Address
- Includes:
- Comparable, Socket::Constants
- Defined in:
- lib/async/io/address.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
- .tcp(*args, **options) ⇒ Object
- .udp(*args, **options) ⇒ Object
- .unix(*args, **options) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #accept(&block) ⇒ Object
- #afamily ⇒ Object (also: #family)
-
#bind(&block) ⇒ Object
def connect? accept? DatagramHandler StreamHandler.
- #connect(&block) ⇒ Object
-
#initialize(specification, **options) ⇒ Address
constructor
A new instance of Address.
- #socktype ⇒ Object (also: #type)
- #to_sockaddr ⇒ Object (also: #to_str)
Constructor Details
#initialize(specification, **options) ⇒ Address
Returns a new instance of Address.
54 55 56 |
# File 'lib/async/io/address.rb', line 54 def initialize(specification, **) super(specification, ) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options
25 26 27 |
# File 'lib/async/io/address.rb', line 25 def @options end |
#specification ⇒ Object
Returns the value of attribute specification
25 26 27 |
# File 'lib/async/io/address.rb', line 25 def specification @specification end |
Class Method Details
.each(specifications, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/async/io/address.rb', line 42 def each(specifications, &block) specifications.each do |specification| if specification.is_a? self yield self else # Perhaps detect options here? yield self.new(specification) end end end |
.tcp(*args, **options) ⇒ Object
30 31 32 |
# File 'lib/async/io/address.rb', line 30 def tcp(*args, **) self.new([:tcp, *args], **) end |
.udp(*args, **options) ⇒ Object
34 35 36 |
# File 'lib/async/io/address.rb', line 34 def udp(*args, **) self.new([:udp, *args], **) end |
.unix(*args, **options) ⇒ Object
38 39 40 |
# File 'lib/async/io/address.rb', line 38 def unix(*args, **) self.new([:unix, *args], **) end |
Instance Method Details
#<=>(other) ⇒ Object
62 63 64 |
# File 'lib/async/io/address.rb', line 62 def <=> other self.to_sockaddr <=> other.to_sockaddr end |
#==(other) ⇒ Object
58 59 60 |
# File 'lib/async/io/address.rb', line 58 def == other self.to_sockaddr == other.to_sockaddr end |
#accept(&block) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/async/io/address.rb', line 104 def accept(&block) backlog = self..fetch(:backlog, SOMAXCONN) bind do |socket| socket.listen(backlog) socket.accept_each(&block) end end |
#afamily ⇒ Object Also known as: family
80 81 82 |
# File 'lib/async/io/address.rb', line 80 def afamily addrinfo.afamily end |
#bind(&block) ⇒ Object
def connect? accept? DatagramHandler StreamHandler
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/async/io/address.rb', line 89 def bind(&block) case specification when Addrinfo Socket.bind(specification, **, &block) when Array Socket.bind(Addrinfo.send(*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
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/async/io/address.rb', line 113 def connect(&block) case specification when Addrinfo, Array Socket.connect(self, &block) when ::BasicSocket yield Async::IO.try_convert(specification) when BasicSocket yield specification else raise ArgumentError, "Not sure how to bind to #{specification}!" end end |
#socktype ⇒ Object Also known as: type
73 74 75 |
# File 'lib/async/io/address.rb', line 73 def socktype addrinfo.socktype end |
#to_sockaddr ⇒ Object Also known as: to_str
66 67 68 |
# File 'lib/async/io/address.rb', line 66 def to_sockaddr addrinfo.to_sockaddr end |