[squeak-dev] Re: Socket CPU usage

Andreas Raab andreas.raab at gmx.de
Fri Jun 12 17:39:57 UTC 2009


Jon Hylands wrote:
> I call Socket >> #receiveDataInto:startingAt: and after a while, CPUWatcher
> complains that that process is taking too much CPU. Note that I'm running
> on an older system (3.8, Update #6665), with the 3.10.6 (release) VM from
> Aug 30, 2007 (on Windows XP).

You might just be hitting a particular issue with that very Socket 
method. If you look at receiveDataInto:startingAt: you will notice that 
when the connection is closed, it notices it but doesn't do anything. 
Because of that, callers need to be aware that *they* must check whether 
the underlying socket has been closed which is not the case with other 
socket methods. For example, consider a loop like here:

index := 1.
[index <= buffer size] whileTrue:[
	count := socket receiveDataInto: buffer startingAt: index.
	index := index + count.
].

This would loop indefinitely if the socket connection gets closed while 
you're in it. To fix this you can either change the caller to test 
explicitly or change that method to raise an error when the closed 
condition is detected.

Hope this helps,
   - Andreas



More information about the Squeak-dev mailing list