qint64 AbstractSerial::readData(char *data, qint64 maxSize){ Q_D(AbstractSerial); qint64 ret = d->serialEngine->read(data, maxSize); if (ret < 0) emitStatusString(EReadDataIO); d->emittedReadyRead = false; return ret;}
int NativeSerialEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite) {...int ret = ::select(fd + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);...}
int ret = ::select(fd + 1, &fdread, 0, 0, timeout < 0 ? 0 : &tv);
int NativeSerialEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite) const{ fd_set fdread; FD_ZERO(&fdread); if (checkRead) FD_SET(fd, &fdread); fd_set fdwrite; FD_ZERO(&fdwrite); if (checkWrite) FD_SET(fd, &fdwrite); struct timeval tv; tv.tv_sec = timeout / 1000; tv.tv_usec = (timeout % 1000) * 1000; //int ret = ::select(fd + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); // <- ЕСЛИ ТАК - ТО НЕ РАБОТАЕТ, А ВСЕГДА ВОЗВРАЩАЕТ 1 int ret = ::select(fd + 1, &fdread, 0, 0, timeout < 0 ? 0 : &tv); // <- ЕСЛИ ТАК -ТО РАБОТАЕТ, НО БЕЗ НОТИФИКАЦИИ ЗАПИСИ if (ret <= 0) return ret; *selectForRead = FD_ISSET(fd, &fdread); *selectForWrite = FD_ISSET(fd, &fdwrite); return ret;}
bool NativeSerialEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs, bool *timedOut) const{ Q_D(const NativeSerialEngine); int ret = d->nativeSelect(msecs, checkRead, checkWrite, readyToRead, readyToWrite); if (ret == 0) { if (timedOut) *timedOut = true; if (checkRead) { // } if (checkWrite) { // } return false; } return ret > 0;}
bool AbstractSerial::waitForReadyRead(int msecs){ Q_D(AbstractSerial); if (!isOpen()) { emitStatusString(EDeviceIsNotOpen); return false; } QTime stopWatch; stopWatch.start(); d->stopSerialNotifiers(); forever { bool readyToRead = false; bool readyToWrite = false; if (!d->serialEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, true, qt_timeout_value(msecs, stopWatch.elapsed()))) { emitStatusString(EWaitReadyReadTimeout); d->startSerialNotifiers(); return false; } if (readyToRead) { d->waitForReadyReadCalled = true; if (d->canReadNotification()) { d->startSerialNotifiers(); return true; } } if (readyToWrite) d->canWriteNotification(); }}