I have next code:
int main()
{
OwnSelect(23, FD_READ | FD_WRITE); // <---- Several arguments as one
return 0;
}
int OwnSelect(SOCKET s, long lNetworkEvents)
{
// How can i check that FD_READ has been passed?
if(lNetworkEvents == FD_READ)
{
// never here
}
return 0;
}
How can i check that FD_READ has been passed no matter if another FD has been passed with FD_READ.
Thanks!
Seems like you’re missing out on a bit of basic bit manipulation here. You’re OR’ing FD_READ and FD_WRITE (| = bitwise OR), thereby setting the bits indicated by both values, as a parameter. To check if FD_READ was passed, you need to AND lNetworkEvents with FD_READ and check if the result equals FD_READ, like so:
if (FD_READ == (lNetworkEvents & FD_READ)) { ... }
This of course assuming that FD_READ and FD_WRITE are values that were meant to be used this way (i.e. typically don’t have overlapping bits).
edit: fixed, wabepper is absolutely right 🙂 oops!