Select()函数不起作用

时间:2014-04-09 23:19:23

标签: c++ select posix

我无法获取以下代码以通过select()函数。它会一直到#34;之前的#34;并且不会在...之后打印出""。这不是编译时错误,但更可能是线程或我没有看到的其他东西。

    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 ;

0 个答案:

没有答案