tk03
05-06-2003, 10:42 PM
I'm trying to use select() to suspend my program until data is available on the descriptors in a list. But for some reason select just doesn't work. The only time my program is allowed to run is after the timeout but not when data is available. The primary descriptor I'm using it with is the descriptor returned by ConnectionNumber() in Xlib so that my program can have a GUI and work with sockets in the same process/thread.
The code I use is this:
myList.push_back(ConnectionNumber (dpy));
int highestFD = myList[0];
while (1)
{
tv.tv_usec = 0;
tv.tv_sec = 1;
FD_ZERO(&fd);
for(unsigned int i = 0;i<myList.size();++i)
{
FD_SET(myList[i], &fd);
if(myList[i] > highestFD)
highestFD = myList[i];
}
select (highestFD+1, &fd, 0, 0, &tv);
//prints data to shell to see that it worked.
}
Am I misusing this function or is this a bug in the system libraries? Note, the OS I'm using is Gentoo Linux(Arch: x86).
The code I use is this:
myList.push_back(ConnectionNumber (dpy));
int highestFD = myList[0];
while (1)
{
tv.tv_usec = 0;
tv.tv_sec = 1;
FD_ZERO(&fd);
for(unsigned int i = 0;i<myList.size();++i)
{
FD_SET(myList[i], &fd);
if(myList[i] > highestFD)
highestFD = myList[i];
}
select (highestFD+1, &fd, 0, 0, &tv);
//prints data to shell to see that it worked.
}
Am I misusing this function or is this a bug in the system libraries? Note, the OS I'm using is Gentoo Linux(Arch: x86).