× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Rick,

    C                   If        Bytesread <= 0
    C                   Call(e)   'SLEEPCL'
    C                   Parm      '000001'      Delay
    C                   Eval      RecvTries += 1

What's this about?! I would definitely assume that this is the problem. When the recv() API returns a number <= 0, there's an error. You need to check errno and handle it appropriately.

If the error is EAGAIN, then there's no data to read at the moment. In which case you should use the select() API to wait until there's data. You should NOT simply delay for a second!

I suspect that what's happening is that the system is trying to send you data very quickly... if it's a 10 megabit connection, it'd be sending you something like 100 kilobytes a second, right? (give or take). You have an 8k socket buffer to receive data into. So this is what you do:

a) Read everything that's on the socket (at most, 8k)

b) Try to read again -- this'll happen instantly, because the computer is waaaaay faster than the network. So recv() will return 0.

c) You sleep for 1 second. During that time, Windows tries to send you 100k of information, but since you only have 8k in your buffer, Windows can only send 8k before stopping.

d) Go back to step (a).

This results in an 8k/second transfer rate, because your program keeps stopping the receive process for 1 second intervals. Actually, that's not entirely accurate, because it's possible that Windows will get a few bytes into the buffer in between the recv() and the next recv() call, so you might not always hit the sleep... based on your benchmarks, I'd guess that it's hitting the 1 second sleep about half of the time.

The fix is easy... get rid of the SLEEPCL and use the select() API to wait for data on the socket.

Tell select() that you want to:

a) Wait until 1 second has elapsed.
-- or --
b) Until there's data to read on the socket.

So if there's data to receive, it doesn't sit and wait -- it immediately reads it. If there isn't data, it waits and doesn't consume CPU time. That's what the select() API is designed for.

Though, actually, I wouldn't use a 1 second delay time on the select(). Since it'll resume processing as soon as there's data, you no longer need to keep checking every second. You can just set the timeout to be 28800 seconds or whatever you think a reasonable time to wait would be. I don't know if there are long "lulls" in the conversation or not.

OF course, 28800 is a long time to wait for an error. Unless it's normal to have long delays between receiving data (for example, when waiting for a user), I'd set the timeout to something more like 30 seconds. But that's neither here nor there... your problem is almost certainly the call to SLEEPCL.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.