Devolus
Devolus

Reputation: 22104

pselect problems with FD_ISSET on cygwin

I'm running cygwin and use pselect to monitor a socket and filedescriptors for child processes.

According to some example that I found here http://www.linuxprogrammingblog.com/code-examples/using-pselect-to-avoid-a-signal-race and the man pages pselect should return the number of filedescriptors which are set in the mask fields (http://linux.die.net/man/2/pselect).

Now when I connect to my server pselect returns, which is fine. But when I test for the filedescriptors using FD_ISSET they always return true:

FD_ZERO(&readers);
FD_ZERO(&writers);
FD_ZERO(&exceptions);

FD_SET(fileno(stdin), &readers);
FD_SET(socket, &readers);
pret = pselect(FD_SETSIZE, &readers, &writers, &exceptions, NULL, &mSignalMask);

, &readers, &writers, &exceptions, NULL, &mSignalMask);

if(pret <= 0)
{
    // ignore for now
    continue;
}

if(FD_ISSET(fileno(stdin), &readers))
{
    string s;
    cin >> s;
    cout << "stdin: " << s << endl;  // blocks because the code always gets here even when 
                // pselect returns because of a childsignal without any data.
    continue;
 }

if(FD_ISSET(socket, &readers))
{
    accept();   // blocks because the code always gets here even when 
                // pselect returns because of a childsignal without any data.
    cout << "task created connection from " <<task->getClientHost() << endl;
    continue;
}

Upvotes: 1

Views: 278

Answers (1)

Devolus
Devolus

Reputation: 22104

Found the problem myself. FD_ISSET can ONLY be used if the result from pselect is > 0, otherweise the returnvalue from FD_ISSET is as before the call. So best treat it as undefined when pselect returns <= 0;

Upvotes: 1

Related Questions