IPSocketAddress.st
changeset 1273 03afdf3f895e
parent 1262 d3daddd36a99
child 1281 6df4f8f211e3
--- a/IPSocketAddress.st	Mon Jul 14 07:27:47 2003 +0200
+++ b/IPSocketAddress.st	Mon Jul 14 13:10:40 2003 +0200
@@ -14,11 +14,18 @@
 
 SocketAddress variableByteSubclass:#IPSocketAddress
 	instanceVariableNames:''
-	classVariableNames:'NameCache AddrCache'
+	classVariableNames:''
 	poolDictionaries:''
 	category:'OS-Sockets'
 !
 
+IPSocketAddress class instanceVariableNames:'addrCache nameCache'
+
+"
+ No other class instance variables are inherited by this class.
+"
+!
+
 !IPSocketAddress class methodsFor:'documentation'!
 
 copyright
@@ -75,9 +82,7 @@
         ^ super hostName:name serviceName:portNrOrName type:socketTypeSymbol
     ].
 
-    AddrCache notNil ifTrue:[
-        addrBytes := AddrCache at:name ifAbsent:nil.
-    ].
+    addrBytes := self addressCacheAt:name.
     addrBytes notNil ifTrue:[
         sa := self hostAddress:addrBytes.
         portNrOrName notNil ifTrue:[
@@ -86,10 +91,7 @@
     ] ifFalse:[
         sa := super hostName:name serviceName:portNrOrName type:socketTypeSymbol.
 
-        (AddrCache isNil or:[AddrCache size > 30]) ifTrue:[
-            AddrCache := Dictionary new
-        ].
-        AddrCache at:name put:(sa hostAddress).
+        self addressCacheAt:name put:(sa hostAddress).
     ].
     ^ sa
 
@@ -138,14 +140,48 @@
     ^ #[0 0 0 0]
 ! !
 
-!IPSocketAddress class methodsFor:'misc'!
+!IPSocketAddress class methodsFor:'caching'!
+
+addressCacheAt:aHostName
+    addrCache notNil ifTrue:[
+        ^ addrCache at:aHostName ifAbsent:nil.
+    ].
+    ^ nil
+!
+
+addressCacheAt:aName put:aHostAddress
+    (addrCache isNil or:[addrCache size > 30]) ifTrue:[
+        addrCache := Dictionary new.
+    ].
+    
+    addrCache at:aName put:aHostAddress.
+!
 
 flushAddressCache
-    AddrCache := nil
+    addrCache := nil
 
     "
      self flushAddressCache
     "
+!
+
+flushNameCache
+    nameCache := Dictionary new.
+!
+
+nameCacheAt:aHostAddress
+    nameCache notNil ifTrue:[
+        ^ nameCache at:aHostAddress ifAbsent:nil.
+    ].
+    ^ nil
+!
+
+nameCacheAt:aHostAddress put:aName
+    (nameCache isNil or:[nameCache size > 30]) ifTrue:[
+        nameCache := Dictionary new.
+    ].
+    
+    nameCache at:aHostAddress put:aName.
 ! !
 
 !IPSocketAddress class methodsFor:'queries'!
@@ -226,19 +262,16 @@
 !IPSocketAddress methodsFor:'queries'!
 
 hostName
-    |name|
+    |addr name|
 
-    NameCache notNil ifTrue:[
-        name := NameCache at:(self hostAddress) ifAbsent:nil.
-        name notNil ifTrue:[^ name].
-    ].
+    addr := self hostAddress.
+
+    name := self class nameCacheAt:addr.
+    name notNil ifTrue:[^ name].
 
     name := super hostName.
     name notNil ifTrue:[
-        (NameCache isNil or:[NameCache size > 30]) ifTrue:[
-            NameCache := Dictionary new
-        ].
-        NameCache at:(self hostAddress) put:name.
+        self class nameCacheAt:addr put:name.
     ].
     ^ name
 ! !
@@ -246,5 +279,5 @@
 !IPSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.21 2003-07-09 15:31:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.22 2003-07-14 11:10:40 cg Exp $'
 ! !