On 12.07.2011 13:38, Sven Van Caekenberghe wrote:
Hi All,
I encountered something that I do not understand. I tried this in 1.2.2 and 1.4 with both my normal, older CogVM as well as the lastest one by Estaban.
In a normal clean image, there would be not Socket instances.
Socket allInstances size = 0
Now create any kind of Socket
Socket new (or newTCP, newUDP)
Now
Socket allInstances size = 2
So Smalltalk reports two instances, but it seems they share the same socketHandle and semaphores, so one seems to be a shallow copy of the other.
(Close the one instance, 3 timesRepeat: [ Smalltalk garbageCollect ] and they are both gone).
Is this normal ? Is there really only one OS level socket ? Does this have to do with Sockets being in a WeakRegistry ?
It is confusing to say the least.
Sven Yes it's normal, one is the finalizer of the other.
To differentiate them more easily, you could do Socket >> actAsFinalizer socketHandle := socketHandle bitInvert. and finalize self primSocketDestroyGently: socketHandle bitInvert. This will (99.9% likely at least) give a printstring of invalidSocketHandle for the finalizing Socket instance. Cheers, Henry