--- a/SocketAddress.st Thu Nov 08 15:03:20 2007 +0100
+++ b/SocketAddress.st Thu Nov 08 15:03:27 2007 +0100
@@ -70,6 +70,57 @@
!SocketAddress class methodsFor:'instance creation'!
+allForHostName:name
+ "get a collection of new instances given a hostname"
+
+ ^ self allForHostName:name serviceName:nil type:nil
+!
+
+allForHostName:name port:portNr
+ "get a collection of new instances given a hostname and port"
+
+ ^ self allForHostName:name serviceName:portNr type:nil
+!
+
+allForHostName:name serviceName:portNrOrName type:socketTypeSymbol
+ "get a collection of new instances given a hostname, port or service and type.
+ Multi-homed hosts return more than one entry"
+
+ |addressInfo serviceName port|
+
+ portNrOrName isString ifTrue:[
+ serviceName := portNrOrName
+ ] ifFalse:[
+ port := portNrOrName.
+ ].
+
+ addressInfo := self
+ getAddressInfo:name
+ serviceName:serviceName
+ domain:(self domainSymbol)
+ type:socketTypeSymbol
+ protocol:nil
+ flags:0.
+
+ ^ addressInfo
+ collect:[:eachAddressInfo|
+ |sa|
+ sa := eachAddressInfo socketAddress.
+ port notNil ifTrue:[
+ sa port:port.
+ ].
+ sa
+ ]
+
+
+ "
+ SocketAddress allForHostName:'localhost' serviceName:10 type:#stream
+ IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram
+ IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:nil
+ IPSocketAddress allForHostName:'google.com' serviceName:'http' type:nil
+ "
+!
+
anyHost
"get a new instance representing the ANY-host address"
@@ -111,41 +162,27 @@
!
hostName:name serviceName:portNrOrName type:socketTypeSymbol
- "get a new instance given a hostname, port or service and type"
-
- |addressInfo serviceName port sa|
+ "get a new instance given a hostname, port or service and type.
+ Do not use this, since it does not work for multi-homed hosts"
- portNrOrName isString ifTrue:[
- serviceName := portNrOrName
- ] ifFalse:[
- port := portNrOrName.
- ].
+ |addressList sa|
- addressInfo := self
- getAddressInfo:name
- serviceName:serviceName
- domain:(self domainSymbol)
- type:socketTypeSymbol
- protocol:nil
- flags:0.
-
- sa := addressInfo first socketAddress.
- addressInfo size > 1 ifTrue:[
- (addressInfo contains:[:entry| entry socketAddress ~= sa]) ifTrue:[
- ('SocketAddress [warning]: multiple hostAddresses for host: ',name) infoPrintCR.
- addressInfo do:[:entry| ' ' infoPrint. entry infoPrintCR].
- (addressInfo detect:[:entry| entry socketAddress ~= sa] ifNone:nil) infoPrintCR.
+ addressList := self allForHostName:name serviceName:portNrOrName type:socketTypeSymbol.
+ sa := addressList first.
+ addressList size > 1 ifTrue:[
+ (addressList contains:[:entry| entry ~= sa]) ifTrue:[
+ ('SocketAddress [warning]: multiple hostAddresses for host: ', name) infoPrintCR.
+ addressList do:[:entry| ' ' infoPrint. entry infoPrintCR].
+ (addressList detect:[:entry| entry ~= sa] ifNone:nil) infoPrintCR.
].
].
- port notNil ifTrue:[
- sa port:port.
- ].
- ^ sa
+ ^ sa.
"
SocketAddress hostName:'localhost' serviceName:10 type:#stream
IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram
IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil
+ IPSocketAddress hostName:'www.google.com' serviceName:'http' type:nil
"
!
@@ -697,5 +734,5 @@
!SocketAddress class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.26 2007-09-25 09:21:45 mb Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.27 2007-11-08 14:03:27 stefan Exp $'
! !