I am really bothered by the timeout on the accept, so much so that I think it 
has no place in the tests.  Of course, one needs a way to clean up after a 
failure, but that should be done by another thread that waits for a "long" time 
and then cleans up anything that is left behind after the failure.

Servers should be started and stopped and in between, they should wait for and 
accept connections.  Clients should try to connect until told otherwise; 
timeouts can be reasonable options there, but should not be forced by the 
sockets system.  Only the calling threads should be blocked, of course.




________________________________________
From: pharo-project-boun...@lists.gforge.inria.fr 
[pharo-project-boun...@lists.gforge.inria.fr] On Behalf Of mkobe...@gmail.com 
[mkobe...@gmail.com]
Sent: Friday, January 14, 2011 1:12 AM
To: Pharo-project@lists.gforge.inria.fr
Subject: Re: [Pharo-project] Socket question (Was Re: Xtreams up to date)

BTW, would this snippet be useful as a basic Socket smoke test ? Or is that 
already covered somewhere ?

| input output listener process sync |
sync := Semaphore new.
listener := Socket newTCP.
listener listenOn: 9999 backlogSize: 10.
process := [
        [       input := listener waitForAcceptFor: 10.
                sync signal
        ] ensure: [ listener close ]
] fork.
output := Socket newTCP.
output connectTo: #[127 0 0 1] port: 9999.
sync wait.
[       #( 64 1024 2048 4096 8192 ) do: [:dataSize || data |
                data := ByteArray new: dataSize.
                1 to: data size do: [:i | data at: i put: (i - 1) \\ 256].
                1 to: 10 do: [:each | output sendData: data].
                1 to: 10 do: [ :each || result index |
                        index := 1.
                        result := ByteArray new: dataSize.
                        [       index := index + (input receiveDataInto: result 
startingAt: index).
                                index > dataSize ] whileFalse.
                        result = data ifFalse: [ result halt]]]
] ensure: [ output close. input close ]


Reply via email to