sockets - pselect problems with FD_ISSET on cygwin -


i'm running cygwin , use pselect monitor socket , filedescriptors child processes.

according example found here http://www.linuxprogrammingblog.com/code-examples/using-pselect-to-avoid-a-signal-race , man pages pselect should return number of filedescriptors set in mask fields (http://linux.die.net/man/2/pselect).

now when connect server pselect returns, fine. when test filedescriptors using fd_isset 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     continue; }  if(fd_isset(fileno(stdin), &readers)) {     string s;     cin >> s;     cout << "stdin: " << s << endl;  // blocks because code gets here when                  // pselect returns because of childsignal without data.     continue;  }  if(fd_isset(socket, &readers)) {     accept();   // blocks because code gets here when                  // pselect returns because of childsignal without data.     cout << "task created connection " <<task->getclienthost() << endl;     continue; } 

found problem myself. fd_isset can used if result pselect > 0, otherweise returnvalue fd_isset before call. best treat undefined when pselect returns <= 0;


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -