summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/serialport/qserialport.cpp5
-rw-r--r--src/serialport/qserialport_p.h9
-rw-r--r--src/serialport/qserialport_unix.cpp2
-rw-r--r--src/serialport/qserialport_win.cpp8
4 files changed, 13 insertions, 11 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index fa780f3..65fcfbb 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -101,7 +101,7 @@ QSerialPortPrivate::QSerialPortPrivate()
, isBreakEnabled(false)
#if defined(Q_OS_WIN32)
, handle(INVALID_HANDLE_VALUE)
- , readChunkBuffer(ReadChunkSize, 0)
+ , readChunkBuffer(QSERIALPORT_BUFFERSIZE, 0)
, communicationStarted(false)
, writeStarted(false)
, readStarted(false)
@@ -121,7 +121,8 @@ QSerialPortPrivate::QSerialPortPrivate()
, writeSequenceStarted(false)
#endif
{
- writeBufferChunkSize = InitialBufferSize;
+ writeBufferChunkSize = QSERIALPORT_BUFFERSIZE;
+ readBufferChunkSize = QSERIALPORT_BUFFERSIZE;
}
void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo)
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index 7512da0..a81cc4b 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -97,6 +97,10 @@ struct serial_struct {
# error Unsupported OS
#endif
+#ifndef QSERIALPORT_BUFFERSIZE
+#define QSERIALPORT_BUFFERSIZE 32768
+#endif
+
QT_BEGIN_NAMESPACE
class QWinOverlappedIoNotifier;
@@ -120,11 +124,6 @@ class QSerialPortPrivate : public QIODevicePrivate
{
Q_DECLARE_PUBLIC(QSerialPort)
public:
- enum IoConstants {
- ReadChunkSize = 512,
- InitialBufferSize = 16384
- };
-
QSerialPortPrivate();
bool open(QIODevice::OpenMode mode);
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 8f9f087..0c79b47 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -769,7 +769,7 @@ bool QSerialPortPrivate::readNotification()
// Always buffered, read data from the port into the read buffer
qint64 newBytes = buffer.size();
- qint64 bytesToRead = ReadChunkSize;
+ qint64 bytesToRead = QSERIALPORT_BUFFERSIZE;
if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) {
bytesToRead = readBufferMaxSize - buffer.size();
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 43660ff..67c68ee 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -355,7 +355,7 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs)
if (overlapped == &readCompletionOverlapped) {
const qint64 readBytesForOneReadOperation = qint64(buffer.size()) - currentReadBufferSize;
- if (readBytesForOneReadOperation == ReadChunkSize) {
+ if (readBytesForOneReadOperation == QSERIALPORT_BUFFERSIZE) {
currentReadBufferSize = buffer.size();
} else if (readBytesForOneReadOperation == 0) {
if (initialReadBufferSize != currentReadBufferSize)
@@ -481,7 +481,7 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred)
readStarted = false;
bool result = true;
- if (bytesTransferred == ReadChunkSize
+ if (bytesTransferred == QSERIALPORT_BUFFERSIZE
|| queuedBytesCount(QSerialPort::Input) > 0) {
result = startAsyncRead();
} else if (readBufferMaxSize == 0
@@ -538,7 +538,7 @@ bool QSerialPortPrivate::startAsyncRead()
if (readStarted)
return true;
- DWORD bytesToRead = ReadChunkSize;
+ DWORD bytesToRead = QSERIALPORT_BUFFERSIZE;
if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) {
bytesToRead = readBufferMaxSize - buffer.size();
@@ -549,6 +549,8 @@ bool QSerialPortPrivate::startAsyncRead()
}
}
+ Q_ASSERT(int(bytesToRead) <= readChunkBuffer.size());
+
::ZeroMemory(&readCompletionOverlapped, sizeof(readCompletionOverlapped));
if (::ReadFile(handle, readChunkBuffer.data(), bytesToRead, nullptr, &readCompletionOverlapped)) {
readStarted = true;