C++ Select()函数不起作用
我在获取以下代码以通过select函数时遇到问题。它将使它的所有方式的权利之前,将不会打印出来的权利之后。。。。这不是一个编译时错误,但更可能是线程或其他我没有看到的东西C++ Select()函数不起作用,c++,select,posix,C++,Select,Posix,我在获取以下代码以通过select函数时遇到问题。它将使它的所有方式的权利之前,将不会打印出来的权利之后。。。。这不是一个编译时错误,但更可能是线程或其他我没有看到的东西 void* eventHandlerLoop(void* c) { vector<RequestChannel*> requestChannels; vector<Item> itemsWaiting; RequestChannel chan1("control", Re
void* eventHandlerLoop(void* c) {
vector<RequestChannel*> requestChannels;
vector<Item> itemsWaiting;
RequestChannel chan1("control", RequestChannel::CLIENT_SIDE);
for ( int i = 0; i < numWorkers ; i++ ) {
string reply = chan1.send_request("newthread");
RequestChannel* channel = new RequestChannel(reply, RequestChannel::CLIENT_SIDE);
requestChannels.push_back(channel);
}
//fill up with requests
for (int i = 0; i < numWorkers; i++ ) {
//prime the pump put input in
//requestChannels[i]::cwrite(mainBuffer->pop.stringVal) ;
itemsWaiting.push_back( mainBuffer->pop() );
}
//sending request from the vec full of items
for (int i = 0; i < numWorkers; i++) {
//RequestChannel::
//cout<< "rrr" << itemsWaiting[i].stringVal << endl;
write(requestChannels[i]->write_fd(), itemsWaiting[i].stringVal.c_str() , itemsWaiting[i].stringVal.length() );
}
while (true) {
fd_set read_fd_set;
FD_ZERO(&read_fd_set);
for (int i = 0; i < numWorkers; i++) {
//FD_SET( RequestChannel::read_fs(), &read_fd_set );
FD_SET( requestChannels[i]->read_fd(), &read_fd_set);
//readFDs.push_back(requestChannels[i]::read_fs());
}
//int numReady = 0;
cout<<"right before the select call " << endl ;
cout<< select( (numWorkers) , &read_fd_set, NULL, NULL, NULL) ;
cout<<"right after the select call " << endl ;
如果select阻塞,则表示描述符尚未准备好读取。为什么会出现这种情况可能是更重要的问题。你没有传递任何超时信息,所以希望它永远阻止,直到问题解决。同意@WhozCraig。您确定描述符已准备好读取吗?如果程序在命令行上运行并且不使用stdin,则始终可以将0添加到集合、FD_SET0和read_FD_set中,然后按一个键。这将为您提供输入并选择返回。不要忘记碰撞numWorkers。您要选择的第一个参数是错误的。必须将其设置为存储在read_fd_set+1中的最高描述符值。你没有那样做。这在Windows上并不重要,但在其他平台上非常重要。NumWorkers是传递给该参数的错误值。感谢您为此问题投入的时间。我已经做出了这些改变,但没有任何帮助。问题是我制造的其他东西。我照原样交,谢谢。