@@ -2,8 +2,8 @@ require "socket"
22
33module LavinMQ
44 class ConnectionInfo
5- getter remote_address : IPAddress
6- getter local_address : IPAddress
5+ getter remote_address : Address
6+ getter local_address : Address
77 property? ssl : Bool = false
88 property? ssl_verify : Bool = false
99 property ssl_version : String ?
@@ -14,18 +14,12 @@ module LavinMQ
1414
1515 # Remote and local addresses from the server's perspective
1616 def initialize (remote_address, local_address)
17- @remote_address = IPAddress .new(remote_address)
18- @local_address = IPAddress .new(local_address)
19- end
20-
21- def self.local
22- src = Socket ::IPAddress .new(" 127.0.0.1" , 0 )
23- dst = Socket ::IPAddress .new(" 127.0.0.1" , 0 )
24- new(src, dst)
17+ @remote_address = Address .new(remote_address)
18+ @local_address = Address .new(local_address)
2519 end
2620
2721 # Suspecting memory problem with Socket::IPAddress in Crystal 1.15.0
28- struct IPAddress
22+ struct Address
2923 getter address : String
3024 getter port : UInt16
3125
@@ -35,25 +29,25 @@ module LavinMQ
3529 end
3630
3731 def initialize (address : String )
38- # is unix
39- if address.starts_with(" /" )
32+ if address.starts_with? " /"
4033 @address = address
4134 @port = 0
4235 return
4336 end
44- parts = address.split(" :" );
45- if parts.length != 2
37+ parts = address.split(" :" )
38+ if parts.size != 2
4639 raise " Socket address should be host:port"
4740 end
48- return self .new(Socket ::IPAddress .new(parts[0 ], parts[1 ].to_u16))
41+ @address = parts[0 ]
42+ @port = parts[1 ].to_u16
4943 end
5044
5145 def to_s (io )
5246 io << @address << ':' << @port
5347 end
5448
5549 def loopback ?
56- @address == " ::1" || @address .starts_with? " 127."
50+ @address == " ::1" || @address .starts_with?( " 127." ) || @address .starts_with?( " / " )
5751 end
5852 end
5953 end
0 commit comments