Merijn Bosma wrote:
> I've been using ICS for quite a while now, and a few days ago I came
> across something strange.
> One of our larger customers had some extra modules installed, causing
> a lot of more tcp clients connecting to the tcp server.
> Every now and then (somewhere between 1 minute and 3 hours) the tcp
> server would get up to 100% cpu utilization out of the blue.
> After some searching we discovered that this was caused by the
> OnDataAvailable event for one of the connected clients being
> called continuously.
> Now the mystery:
> If I understood correct, you can get an endless loop if you don't read
> all received data in the OnDataAvailable event. 

You get a real infinite loop only if you called Receive() with a buffer
size of zero.

> The event will
> keep being fired until all data is read, unless you add
> wsoNoReceiveLoop.

With option wsoNoReceiveLoop turned on OnDataAvailable will also
trigger again and again as long as data is available. The difference is
that the app. is given a chance to call its message pump between two
OnDataAvailable events. As a result CPU utilization becomes lower. This
may however also lower transfer rates a bit.
> The thing is that we _always_ call ReceiveStr() in the OnDataAvailable
> event, I think this should always read all data received.

Depends on LineMode, if LineMode is TRUE ReceiveStr() just reads a
single line.

> Is this a bug in ReceiveStr() or a bug regarding wsoNoReceiveLoop?

I don't think it's a bug, wsoNoReceiveLoop is an option turned off
by default for backwards compatibility.  

Arno Garrels [TeamICS]

To unsubscribe or change your settings for TWSocket mailing list
please goto
Visit our website at

Reply via email to