13 Jan, 2009, Lobotomy wrote in the 1st comment:
Votes: 0
Having gone back to working on my C code again for the sake of my sanity (my frustration over C++ and other languages reached critical mass again, so I'm ditching that effort for the time being), I thought I should get a particular matter cleared up that's been bugging me. I'm fairly certain I know what select() does, thanks to the information here and here, but just to be on the safe side I want to run this matter by Mudbytes to make sure I got this right:

In C Socketmud, the section regarding select within the main game loop looks a little something like this:
/* wait for something to happen */
if (select(FD_SETSIZE, &rFd, NULL, NULL, &tv) < 0)
continue;

Now, personally, according to what I've read about select I first find the comment to be a bit misleading. That ifcheck with select isn't actually "waiting for something to happen", but rather it's checking all file descriptors within the set to see if any can be read from and/or written to. I.e, it's a form of "are these files busy/unavailable right now" check, yes? In a case where they all happen to be busy, the loop starts over and keeps checking until some files are available again? As it stands, because that call is within the socket code the comment makes it sounds as though the select() call means that it is waiting for network input and will avoid moving forward until some kind of input is received; if that is not what is happening, which is what the information about select() leads me to believe, I then feel I need to replace the comment with something a little more accurate.

Anyways, in the off chance that I'm not the only one being thrown off by this (now or in the future), some clarification on the matter would be great. :thinking:
13 Jan, 2009, Davion wrote in the 2nd comment:
Votes: 0
The last argument there &tv, tells select how long it has to timeout. The address is passed to it because it can modify the value to show you how much time was left till the time out. So yes, the select call is actually waiting for something to happen. In this particular case, you're waiting on a read.
13 Jan, 2009, Lobotomy wrote in the 3rd comment:
Votes: 0
Davion said:
The last argument there &tv, tells select how long it has to timeout. The address is passed to it because it can modify the value to show you how much time was left till the time out. So yes, the select call is actually waiting for something to happen. In this particular case, you're waiting on a read.

Ah, I see. Thanks. :thinking:
13 Jan, 2009, Tyche wrote in the 4th comment:
Votes: 0
If &tm is a NULL pointer it will block indefinitely, if it's pointing to zero it will return immediately, and any other value is the MAXIMUM time it will wait.
Don't expect &tm to have any sensible value after the call. Linux happens to modify the time difference left. This is not the case on BSD, OSX, Windows and possibly other Unix flavors.
14 Jan, 2009, David Haley wrote in the 5th comment:
Votes: 0
Tyche is right, the most reliable way to see how much time has passed is to use high-resolution timer functions before and after the select call.
0.0/5