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