Class: MessagePack::RPC::Address
- Inherits:
-
Object
- Object
- MessagePack::RPC::Address
- Defined in:
- lib/msgpack/rpc/address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #==(o) ⇒ Object
- #connectable? ⇒ Boolean
- #dump ⇒ Object
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
- #host ⇒ Object
-
#initialize(host, port) ⇒ Address
constructor
BSD.
- #inspect ⇒ Object
- #port ⇒ Object
- #sockaddr ⇒ Object
- #to_a ⇒ Object
- #to_msgpack(out = '') ⇒ Object
- #to_s ⇒ Object
- #unpack ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Address
BSD
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/msgpack/rpc/address.rb', line 39 def initialize(host, port) raw = Socket.pack_sockaddr_in(port, host) family = raw.unpack('S')[0] if family == Socket::AF_INET @serial = raw[2,6] elsif family == Socket::AF_INET6 @serial = raw[2,2] + raw[8,16] else raise "Unknown address family: #{family}" end end |
Class Method Details
.load(raw) ⇒ Object
101 102 103 |
# File 'lib/msgpack/rpc/address.rb', line 101 def self.load(raw) Address.new *parse(raw) end |
.parse(raw) ⇒ Object
97 98 99 |
# File 'lib/msgpack/rpc/address.rb', line 97 def self.parse(raw) Socket.unpack_sockaddr_in(parse_sockaddr(raw)).reverse end |
.parse_sockaddr(raw) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/msgpack/rpc/address.rb', line 85 def self.parse_sockaddr(raw) if raw.length == 6 addr = Socket.pack_sockaddr_in(0, '0.0.0.0') addr[2,6] = raw[0,6] else addr = Socket.pack_sockaddr_in(0, '::') addr[2,2] = raw[0,2] addr[8,16] = raw[2,16] end addr end |
Instance Method Details
#<=>(o) ⇒ Object
121 122 123 |
# File 'lib/msgpack/rpc/address.rb', line 121 def <=>(o) dump <=> o.dump end |
#==(o) ⇒ Object
137 138 139 |
# File 'lib/msgpack/rpc/address.rb', line 137 def ==(o) eql?(o) end |
#connectable? ⇒ Boolean
73 74 75 |
# File 'lib/msgpack/rpc/address.rb', line 73 def connectable? port != 0 end |
#dump ⇒ Object
105 106 107 |
# File 'lib/msgpack/rpc/address.rb', line 105 def dump @serial end |
#eql?(o) ⇒ Boolean
129 130 131 |
# File 'lib/msgpack/rpc/address.rb', line 129 def eql?(o) o.class == Address && dump.eql?(o.dump) end |
#hash ⇒ Object
133 134 135 |
# File 'lib/msgpack/rpc/address.rb', line 133 def hash dump.hash end |
#host ⇒ Object
65 66 67 |
# File 'lib/msgpack/rpc/address.rb', line 65 def host unpack[0] end |
#inspect ⇒ Object
125 126 127 |
# File 'lib/msgpack/rpc/address.rb', line 125 def inspect "#<#{self.class} #{to_s} @serial=#{@serial.inspect}>" end |
#port ⇒ Object
69 70 71 |
# File 'lib/msgpack/rpc/address.rb', line 69 def port unpack[1] end |
#sockaddr ⇒ Object
77 78 79 |
# File 'lib/msgpack/rpc/address.rb', line 77 def sockaddr Address.parse_sockaddr(@serial) end |
#to_a ⇒ Object
117 118 119 |
# File 'lib/msgpack/rpc/address.rb', line 117 def to_a unpack end |
#to_msgpack(out = '') ⇒ Object
109 110 111 |
# File 'lib/msgpack/rpc/address.rb', line 109 def to_msgpack(out = '') @serial.to_msgpack(out) end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/msgpack/rpc/address.rb', line 113 def to_s unpack.join(':') end |