Logo Search packages:      
Sourcecode: vdccm version File versions

int Multiplexer::multiplex (  ) 

Return values:
0 on select error, if negativ, the absolut values is the number of not processed descriptors, if positiv number of processed descriptors - all ok!

Definition at line 95 of file multiplexer.cpp.

References DescriptorManager::fdSet(), Descriptor::getDescriptor(), DescriptorManager::getHighestDescriptor(), DescriptorManager::process(), and TimerNodeManager::process().

{
    tv = timerNodeManager->process();

    Descriptor* rhDescriptor = readManager->getHighestDescriptor();
    Descriptor* whDescriptor = writeManager->getHighestDescriptor();
    Descriptor* ehDescriptor = exceptionManager->getHighestDescriptor();

    fd_set *rfdSet = NULL;
    int rhfd = 0;

    fd_set *wfdSet = NULL;
    int whfd = 0;

    fd_set *efdSet = NULL;
    int ehfd = 0;


    if (rhDescriptor != NULL) {
        rhfd = rhDescriptor->getDescriptor();
        rfdSet = readManager->fdSet();
    }

    if (whDescriptor != NULL) {
        whfd = whDescriptor->getDescriptor();
        wfdSet = writeManager->fdSet();
    }

    if (ehDescriptor != NULL) {
        ehfd = ehDescriptor->getDescriptor();
        efdSet = exceptionManager->fdSet();
    }

    int maxDesc = 0;

    if (rhfd > whfd) {
        if (ehfd > rhfd) {
            maxDesc = ehfd;
        } else {
            maxDesc = rhfd;
        }
    } else {
        if (ehfd > whfd) {
            maxDesc = ehfd;
        } else {
            maxDesc = whfd;
        }
    }

    int numFds = select(maxDesc + 1, rfdSet, wfdSet, efdSet, &tv);

    int numberProcessed = 0;

    if (numFds > 0) {
        if (numFds != numberProcessed) {
            numberProcessed += readManager->process(Descriptor::READ, rfdSet);
        }

        if (numFds != numberProcessed) {
            numberProcessed += writeManager->process(Descriptor::WRITE, wfdSet);
        }

        if (numFds != numberProcessed) {
            numberProcessed += exceptionManager->process(Descriptor::EXCEPTION, efdSet);
        }
    }

    int ret = 0;

    if (numFds < 0) {
        ret = 0;
    }

    if (numberProcessed == numFds) {
        ret = numberProcessed;
    } else {
        ret = numberProcessed - numFds;
    }

    return ret;
}


Generated by  Doxygen 1.6.0   Back to index