diff options
-rw-r--r-- | src/serialport/qserialport.cpp | 8 | ||||
-rw-r--r-- | src/serialport/qserialport_symbian.cpp | 11 | ||||
-rw-r--r-- | src/serialport/qserialport_symbian_p.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 40 | ||||
-rw-r--r-- | src/serialport/qserialport_unix_p.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 49 | ||||
-rw-r--r-- | src/serialport/qserialport_win_p.h | 5 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 29 |
8 files changed, 10 insertions, 138 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 9c7dbbd6..0a6f2763 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -1062,7 +1062,7 @@ bool QSerialPort::clear(Directions directions) bool QSerialPort::atEnd() const { Q_D(const QSerialPort); - return QIODevice::atEnd() && (!isOpen() || (d->bytesAvailable() == 0)); + return QIODevice::atEnd() && (!isOpen() || (d->readBuffer.size() == 0)); } /*! @@ -1210,7 +1210,7 @@ bool QSerialPort::isSequential() const qint64 QSerialPort::bytesAvailable() const { Q_D(const QSerialPort); - return d->bytesAvailable() + QIODevice::bytesAvailable(); + return d->readBuffer.size() + QIODevice::bytesAvailable(); } /*! @@ -1239,7 +1239,7 @@ qint64 QSerialPort::bytesToWrite() const bool QSerialPort::canReadLine() const { Q_D(const QSerialPort); - const bool hasLine = (d->bytesAvailable() > 0) && d->readBuffer.canReadLine(); + const bool hasLine = (d->readBuffer.size() > 0) && d->readBuffer.canReadLine(); return hasLine || QIODevice::canReadLine(); } @@ -1342,7 +1342,7 @@ bool QSerialPort::setBreakEnabled(bool set) qint64 QSerialPort::readData(char *data, qint64 maxSize) { Q_D(QSerialPort); - return d->readFromBuffer(data, maxSize); + return d->readBuffer.read(data, maxSize); } /*! diff --git a/src/serialport/qserialport_symbian.cpp b/src/serialport/qserialport_symbian.cpp index d905db1a..f22494bc 100644 --- a/src/serialport/qserialport_symbian.cpp +++ b/src/serialport/qserialport_symbian.cpp @@ -248,17 +248,6 @@ qint64 QSerialPortPrivate::systemOutputQueueSize () const return 0; } -qint64 QSerialPortPrivate::bytesAvailable() const -{ - return readBuffer.size(); -} - -qint64 QSerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) -{ - // TODO: Implement me - return -1; -} - qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize) { // TODO: Implement me diff --git a/src/serialport/qserialport_symbian_p.h b/src/serialport/qserialport_symbian_p.h index c56ddaeb..253aa11d 100644 --- a/src/serialport/qserialport_symbian_p.h +++ b/src/serialport/qserialport_symbian_p.h @@ -72,9 +72,6 @@ public: qint64 systemInputQueueSize () const; qint64 systemOutputQueueSize () const; - qint64 bytesAvailable() const; - - qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); bool waitForReadyRead(int msec); diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 8b3d94bc..18f24d85 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -414,46 +414,6 @@ qint64 QSerialPortPrivate::systemOutputQueueSize () const return nbytes; } -qint64 QSerialPortPrivate::bytesAvailable() const -{ - return readBuffer.size(); -} - -qint64 QSerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) -{ - if (readBuffer.isEmpty()) - return 0; - - if (maxSize == 1) { - *data = readBuffer.getChar(); - if (readBuffer.isEmpty()) - setReadNotificationEnabled(true); - return 1; - } - - const qint64 bytesToRead = qMin(qint64(readBuffer.size()), maxSize); - qint64 readSoFar = 0; - while (readSoFar < bytesToRead) { - const char *ptr = readBuffer.readPointer(); - const int bytesToReadFromThisBlock = qMin(int(bytesToRead - readSoFar), - readBuffer.nextDataBlockSize()); - ::memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); - readSoFar += bytesToReadFromThisBlock; - readBuffer.free(bytesToReadFromThisBlock); - } - - if (!isReadNotificationEnabled()) - setReadNotificationEnabled(true); - - if (readSoFar > 0) { - if (readBuffer.isEmpty()) - setReadNotificationEnabled(true); - return readSoFar; - } - - return readSoFar; -} - qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize) { char *ptr = writeBuffer.reserve(maxSize); diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h index 15bb5f8f..7c2b771c 100644 --- a/src/serialport/qserialport_unix_p.h +++ b/src/serialport/qserialport_unix_p.h @@ -111,9 +111,6 @@ public: qint64 systemInputQueueSize () const; qint64 systemOutputQueueSize () const; - qint64 bytesAvailable() const; - - qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); bool waitForReadyRead(int msecs); diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 42d8fbf2..f8873dda 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -243,7 +243,7 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q) : QSerialPortPrivateData(q) , descriptor(INVALID_HANDLE_VALUE) , parityErrorOccurred(false) - , actualReadBufferSize(0) + , readChunkBuffer(ReadChunkSize, 0) , actualWriteBufferSize(0) , acyncWritePosition(0) , readyReadEmitted(0) @@ -323,7 +323,6 @@ void QSerialPortPrivate::close() notifiers.clear(); readBuffer.clear(); - actualReadBufferSize = 0; writeSequenceStarted = false; writeBuffer.clear(); @@ -405,10 +404,8 @@ bool QSerialPortPrivate::flush() bool QSerialPortPrivate::clear(QSerialPort::Directions directions) { DWORD flags = 0; - if (directions & QSerialPort::Input) { + if (directions & QSerialPort::Input) flags |= PURGE_RXABORT | PURGE_RXCLEAR; - actualReadBufferSize = 0; - } if (directions & QSerialPort::Output) { flags |= PURGE_TXABORT | PURGE_TXCLEAR; actualWriteBufferSize = 0; @@ -466,38 +463,6 @@ qint64 QSerialPortPrivate::systemOutputQueueSize () #ifndef Q_OS_WINCE -qint64 QSerialPortPrivate::bytesAvailable() const -{ - return actualReadBufferSize; -} - -qint64 QSerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) -{ - if (actualReadBufferSize == 0) - return 0; - - qint64 readSoFar = -1; - if (maxSize == 1 && actualReadBufferSize > 0) { - *data = readBuffer.getChar(); - actualReadBufferSize--; - readSoFar = 1; - } else { - const qint64 bytesToRead = qMin(qint64(actualReadBufferSize), maxSize); - readSoFar = 0; - while (readSoFar < bytesToRead) { - const char *ptr = readBuffer.readPointer(); - const int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, - qint64(readBuffer.nextDataBlockSize())); - ::memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); - readSoFar += bytesToReadFromThisBlock; - readBuffer.free(bytesToReadFromThisBlock); - actualReadBufferSize -= bytesToReadFromThisBlock; - } - } - - return readSoFar; -} - qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize) { char *ptr = writeBuffer.reserve(maxSize); @@ -706,9 +671,7 @@ bool QSerialPortPrivate::startAsyncRead() return false; } - char *ptr = readBuffer.reserve(bytesToRead); - - if (::ReadFile(descriptor, ptr, bytesToRead, NULL, n->overlappedPointer())) + if (::ReadFile(descriptor, readChunkBuffer.data(), bytesToRead, NULL, n->overlappedPointer())) return true; QSerialPort::SerialPortError error = decodeSystemError(); @@ -717,7 +680,6 @@ bool QSerialPortPrivate::startAsyncRead() error = QSerialPort::ReadError; q->setError(error); - readBuffer.truncate(actualReadBufferSize); return false; } @@ -800,11 +762,10 @@ void QSerialPortPrivate::completeAsyncRead(DWORD numberOfBytes) { Q_Q(QSerialPort); - actualReadBufferSize += qint64(numberOfBytes); - readBuffer.truncate(actualReadBufferSize); - if (numberOfBytes > 0) { + readBuffer.append(readChunkBuffer.left(numberOfBytes)); + // Process emulate policy. if ((policy != QSerialPort::IgnorePolicy) && parityErrorOccurred) { diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h index 414f0267..bd164ff6 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -85,9 +85,6 @@ public: qint64 systemInputQueueSize (); qint64 systemOutputQueueSize (); - qint64 bytesAvailable() const; - - qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); bool waitForReadyRead(int msec); @@ -133,7 +130,7 @@ public: #ifndef Q_OS_WINCE QHash<HANDLE, AbstractOverlappedEventNotifier *> notifiers; - qint64 actualReadBufferSize; + QByteArray readChunkBuffer; qint64 actualWriteBufferSize; qint64 acyncWritePosition; bool readyReadEmitted; diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index 21bea1e7..2983071a 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -253,35 +253,6 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions) return ::PurgeComm(descriptor, flags); } -qint64 QSerialPortPrivate::bytesAvailable() const -{ - return readBuffer.size(); -} - -qint64 QSerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) -{ - if (readBuffer.isEmpty()) - return 0; - - if (maxSize == 1) { - *data = readBuffer.getChar(); - return 1; - } - - const qint64 bytesToRead = qMin(qint64(readBuffer.size()), maxSize); - qint64 readSoFar = 0; - while (readSoFar < bytesToRead) { - const char *ptr = readBuffer.readPointer(); - const int bytesToReadFromThisBlock = qMin(int(bytesToRead - readSoFar), - readBuffer.nextDataBlockSize()); - ::memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); - readSoFar += bytesToReadFromThisBlock; - readBuffer.free(bytesToReadFromThisBlock); - } - - return readSoFar; -} - qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize) { char *ptr = writeBuffer.reserve(maxSize); |