void FileDescriptorMonitor::run() { shouldStop = false; fd_set workingFdSet; timeval pollInterval = {1, 0}; // 1 sec timeval workingPollInterval = pollInterval; while (!shouldStop) { workingFdSet = watchedFdSet; int rval = select(watchedFd + 1, &workingFdSet, NULL, NULL, &workingPollInterval); workingPollInterval = pollInterval; if (rval != -1 && FD_ISSET(watchedFd, &workingFdSet)) { //qDebug() << "readyForRead()"; emit readyForRead(watchedFd); } else { //qDebug() << "select() timeout"; } } qDebug() << "FileDescriptorMonitor exiting"; }
ByteArray UDPInternalConnection::receiveImpl(unsigned long size) { if (readyForRead() == 0) { if (!isPending()) setPending(); else throw netman::SockConnectionError("Already pending"); std::unique_lock<std::mutex> lock(syncMutex); waitVar.wait(lock, [&] {return !isPending();}); if (isTimedOut()) { setIdle(); throw netman::SockRecieveFailed("Operation timeout"); } else setIdle(); } return readBuffer(); }