instance creation refactored
authorClaus Gittinger <cg@exept.de>
Wed, 09 Jul 2003 16:26:27 +0200
changeset 1259 0a557e59ea4a
parent 1258 a0eda4db4dad
child 1260 9a8fb2391174
instance creation refactored (dispatch from Socket via peerFromDomain:name:port:)
AppletalkSocketAddress.st
DecNetSocketAddress.st
IPSocketAddress.st
IPv6SocketAddress.st
SocketAddress.st
SocketAddressInfo.st
UDSocketAddress.st
--- a/AppletalkSocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/AppletalkSocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -54,6 +54,12 @@
 "
 ! !
 
+!AppletalkSocketAddress class methodsFor:'instance creation'!
+
+peerName:peerName port:port
+    ^ self hostAddress:(Socket appletalkAddressOfHost:peerName) port:port
+! !
+
 !AppletalkSocketAddress class methodsFor:'addressing'!
 
 anyNet
@@ -103,7 +109,6 @@
 !
 
 net:aNodeAddress
-
     self unsignedShortAt:4 put:aNodeAddress bigEndian:true
 
     "
@@ -169,5 +174,5 @@
 !AppletalkSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/AppletalkSocketAddress.st,v 1.7 2003-05-21 18:02:52 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/AppletalkSocketAddress.st,v 1.8 2003-07-09 14:26:23 cg Exp $'
 ! !
--- a/DecNetSocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/DecNetSocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -52,6 +52,12 @@
 "
 ! !
 
+!DecNetSocketAddress class methodsFor:'instance creation'!
+
+peerName:peerName port:port
+    ^ self hostAddress:(Socket decnetAddressOfHost:peerName) port:port
+! !
+
 !DecNetSocketAddress class methodsFor:'queries'!
 
 domainSymbol
@@ -70,5 +76,5 @@
 !DecNetSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/DecNetSocketAddress.st,v 1.1 2003-05-21 17:56:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/DecNetSocketAddress.st,v 1.2 2003-07-09 14:26:19 cg Exp $'
 ! !
--- a/IPSocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/IPSocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -97,6 +97,10 @@
      IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram 
      IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil
     "
+!
+
+peerName:peerName port:port
+    ^ self hostAddress:(Socket ipAddressOfHost:peerName) port:port
 ! !
 
 !IPSocketAddress class methodsFor:'addressing'!
@@ -167,7 +171,6 @@
 !
 
 port:aPortNr
-
     self unsignedShortAt:3 put:aPortNr bigEndian:true
 ! !
 
@@ -236,5 +239,5 @@
 !IPSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.18 2003-05-21 21:22:44 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.19 2003-07-09 14:26:11 cg Exp $'
 ! !
--- a/IPv6SocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/IPv6SocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -62,6 +62,12 @@
 "
 ! !
 
+!IPv6SocketAddress class methodsFor:'instance creation'!
+
+peerName:peerName port:port
+    ^ self hostAddress:(Socket ipV6AddressOfHost:peerName) port:port
+! !
+
 !IPv6SocketAddress class methodsFor:'queries'!
 
 domainSymbol
@@ -103,5 +109,5 @@
 !IPv6SocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.8 2003-05-21 21:21:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.9 2003-07-09 14:26:27 cg Exp $'
 ! !
--- a/SocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/SocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -163,6 +163,10 @@
     self newDomain:#unix
     self newDomain:#inet
    "
+!
+
+peerName:peerName port:port
+    self error:'unsupported domain'.
 ! !
 
 !SocketAddress class methodsFor:'queries'!
@@ -321,7 +325,15 @@
     ].
     cls := DomainToClassMapping at:code ifAbsent:nil.
     cls notNil ifTrue:[^ cls].
+
     code notNil ifTrue:[
+        "/ some are always known...
+        DomainToClassMapping at:#unix put:UDSocketAddress.
+        DomainToClassMapping at:#inet put:IPSocketAddress.
+        DomainToClassMapping at:#inet6 put:IPv6SocketAddress.
+        DomainToClassMapping at:#appletalk put:AppletalkSocketAddress.
+        DomainToClassMapping at:#decnet put:DecNetSocketAddress.
+
         self allSubclassesDo:[:aSubClass|
             (aSubClass domainCode == code
             or:[aSubClass domainSymbol == code
@@ -354,6 +366,10 @@
     ^ nil
 !
 
+peerNameFromPeer:peer
+    ^ peer hostName
+!
+
 socketAddressSize
     "answer the OS specific size of a socket address"
 
@@ -375,12 +391,10 @@
 !SocketAddress methodsFor:'accessing'!
 
 domainCode
-
     ^ self unsignedShortAt:1
 !
 
 domainCode:anInteger
-
     self unsignedShortAt:1 put:anInteger
 !
 
@@ -447,8 +461,12 @@
                   wantServiceName:false datagram:false flags:0) first
 
     "
-     (IPSocketAddress hostAddress:#[127 0 0 1] port:7) hostName
-     (IPSocketAddress hostAddress:#[193 141 12 193] port:10) hostName 
+     (IPSocketAddress hostAddress:#[127 0 0 1]) hostName        
+     (IPSocketAddress hostName:'localhost') address        
+     (IPSocketAddress hostName:'www.google.com') address        
+
+     (IPSocketAddress hostAddress:#[127 0 0 1] port:7) hostName        
+     (IPSocketAddress hostAddress:#[193 141 12 193] port:10) hostName  
      (IPSocketAddress hostAddress:#[193 141 12 244]) hostName 
     "
 !
@@ -470,5 +488,5 @@
 !SocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.17 2003-05-21 21:22:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.18 2003-07-09 14:26:06 cg Exp $'
 ! !
--- a/SocketAddressInfo.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/SocketAddressInfo.st	Wed Jul 09 16:26:27 2003 +0200
@@ -11,74 +11,50 @@
 !SocketAddressInfo methodsFor:'accessing'!
 
 canonicalName
-    "return the value of the instance variable 'canonicalName' (automatically generated)"
-
     ^ canonicalName
 !
 
 canonicalName:something
-    "set the value of the instance variable 'canonicalName' (automatically generated)"
-
     canonicalName := something.
 !
 
 domain
-    "return the value of the instance variable 'domain' (automatically generated)"
-
     ^ domain
 !
 
 domain:something
-    "set the value of the instance variable 'domain' (automatically generated)"
-
     domain := something.
 !
 
 flags
-    "return the value of the instance variable 'flags' (automatically generated)"
-
     ^ flags
 !
 
 flags:something
-    "set the value of the instance variable 'flags' (automatically generated)"
-
     flags := something.
 !
 
 protocol
-    "return the value of the instance variable 'protocol' (automatically generated)"
-
     ^ protocol
 !
 
 protocol:something
-    "set the value of the instance variable 'protocol' (automatically generated)"
-
     protocol := something.
 !
 
 socketAddress
-    "return the value of the instance variable 'socketAddress' (automatically generated)"
-
     ^ socketAddress
 !
 
 socketAddress:something
-    "set the value of the instance variable 'socketAddress' (automatically generated)"
-
     socketAddress := something.
 !
 
 type
-    "return the value of the instance variable 'type' (automatically generated)"
-
     ^ type
 !
 
 type:something
-    "set the value of the instance variable 'type' (automatically generated)"
-
     type := something.
 ! !
 
@@ -98,5 +74,5 @@
 !SocketAddressInfo class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddressInfo.st,v 1.2 2003-05-21 13:45:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddressInfo.st,v 1.3 2003-07-09 14:26:15 cg Exp $'
 ! !
--- a/UDSocketAddress.st	Wed Jul 09 14:55:42 2003 +0200
+++ b/UDSocketAddress.st	Wed Jul 09 16:26:27 2003 +0200
@@ -70,6 +70,10 @@
     "
      UDSocketAddress name:'/tmp/aUnixDomainSocket' 
     "
+!
+
+peerName:peerName port:port
+    ^ self name:peerName
 ! !
 
 !UDSocketAddress class methodsFor:'queries'!
@@ -83,6 +87,10 @@
     ^ #unix
 !
 
+peerNameFromPeer:peer
+    ^ 'localhost'
+!
+
 vwDomainSymbol
     ^ #afUnix
 ! !
@@ -90,12 +98,10 @@
 !UDSocketAddress methodsFor:'accessing'!
 
 name
-
     ^ self stringAt:3
 !
 
 name:pathName
-
     self stringAt:3 put:pathName
 ! !
 
@@ -110,25 +116,20 @@
 !
 
 hostName:hostOrPathName port:portNrOrName
-
     self name:hostOrPathName
 !
 
 port:pathName
-
     self name:pathName
 !
 
 portOrName
-
     ^ self name
 ! !
 
 !UDSocketAddress methodsFor:'printing & storing'!
 
 printOn:aStream
-
-
     aStream nextPutAll:self class name; 
             nextPut:$(; nextPutAll:self name; nextPut:$)
 
@@ -140,5 +141,5 @@
 !UDSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/UDSocketAddress.st,v 1.10 2003-05-21 18:02:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/UDSocketAddress.st,v 1.11 2003-07-09 14:26:02 cg Exp $'
 ! !