> I'm using NetLibSelect to block while waiting for input on either a network socket
>or stdin (eg penDown etc). I'm passing a timeout value of
> SysTicksPerSecond() - so it should timeout after 1 second... but it
> doesn't... :-(
>
I don't think your code is quite right... I'm using very similar code
(using the select() call) and it does work as advertised.
> Any ideas? Here's a code snippet...
>
> NetFDSetType rFDs, wFDs, eFDs;
> SWord numFDs;
> Word MaxRefNum = sysFileDescStdIn;
> Word timeOut = SysTicksPerSecond();
>
> netFDZero( &rFDs );
> netFDZero( &wFDs );
> netFDZero( &eFDs );
>
> netFDSet( sysFileDescStdIn, &rFDs );
> netFDSet( mySocketRef, &rFDs );
>
One problem here... timeOut is a Long, not a Word, so this is probably
why your call isn't timing out!
>
> if ( mySocket > maxRefNum )
> maxRefNum = mySocket;
>
Instead of this, I'm using:
MaxRefNum = mySocketRef + 1;
>
> numFDs = NetLibSelect( myNetRefNum, maxRefNum + 1, &rFDs, &wFDs, &eFDs, timeOut,
>&mtNetError );
>
If you use the above code, then just use maxRefNum in the call to
NetLibSelect. And make sure timeOut is a Long.
>
> if ( numFDs == 0 ) // timout has occured
> {
> // Do something...
> }
>
Oops! as it says in the Docs... numFDs is -1 when the select times out,
and then you test mtNetError == netErrTimeout to detect the timeout.
Something like this:
If (numFDs < 0) { // some error
if (mtNetError == netErrTimeout) {
// select timed out
}
}
else {
// some FD is ready to read...
}
> It never seems to timeout, so the 'if' test never evaluates to true... also it only
>*seems* to respond to user events the first time round... ie
> network events on the socket don't cause NetLibSelect to return... after
> an initial whack on the screen with my stylus it will then start
> responding to incoming network events on the socket...
>
I'd guess that the no timeout behavior is because of the Word vs. Long
use for the timeout val, and changing the way MaxRefNum is computed will
fix it not detecting ready FDs correctly. Finally, updating the error
testing will let you detect timeouts correctly.
--
John Schettino - http://members.tripod.com/schettino/
CORBA For Dummies, AppleScript Applications, and more.