summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2013-12-30 17:03:42 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-30 14:05:13 +0100
commitcb2dd80a4fce3a190be121c80486c6ba407f5fbf (patch)
tree2f6fe96954c1edbbde5ca18f6f464246ca383c0f
parent25a17db97a8549e5415d23ba1064e4259930ce7f (diff)
downloadqtserialport-cb2dd80a4fce3a190be121c80486c6ba407f5fbf.tar.gz
Reimplement low level data sending
A feature of writing of the buffer by chunks of 512 bytes (by default) was introduced earlier as the developers option in order that it was possible to regulate load of the CPU and quantity of emitted signals of bytesWritten() just change WriteChunkSize value in source code. As shows of the practice, the most optimal mode is writing of whole content of the buffer without division into chunks. It reduces load of CPU (because reduces a quantity of the events triggers) and also simplifies the source code. But potentially there can be negative consequences of writing of whole buffer directly in case of broken driver: * A kernel panic (or BSOD) in case of writing a data large than driver's internal queue. * Can be transferred not all data from the buffer, but only their part. Change-Id: I0fcac1ccf3c752579978b4745771accbf8274267 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_p.h3
-rw-r--r--src/serialport/qserialport_unix.cpp10
-rw-r--r--src/serialport/qserialport_unix_p.h2
-rw-r--r--src/serialport/qserialport_win.cpp8
-rw-r--r--src/serialport/qserialport_win_p.h4
-rw-r--r--src/serialport/qserialport_wince.cpp12
6 files changed, 18 insertions, 21 deletions
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index 4140493..2166b47 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -54,8 +54,7 @@ class QSerialPortPrivateData
{
public:
enum IoConstants {
- ReadChunkSize = 512,
- WriteChunkSize = 512
+ ReadChunkSize = 512
};
QSerialPortPrivateData(QSerialPort *q);
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 51bb01e..9571767 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -133,7 +133,7 @@ protected:
bool event(QEvent *e) Q_DECL_OVERRIDE {
bool ret = QSocketNotifier::event(e);
if (ret)
- dptr->writeNotification(QSerialPortPrivateData::WriteChunkSize);
+ dptr->writeNotification();
return ret;
}
@@ -455,7 +455,7 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs)
}
if (readyToWrite)
- writeNotification(WriteChunkSize);
+ writeNotification();
} while (msecs == -1 || timeoutValue(msecs, stopWatch.elapsed()) > 0);
return false;
@@ -487,7 +487,7 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs)
return false;
if (readyToWrite)
- return writeNotification(WriteChunkSize);
+ return writeNotification();
}
return false;
}
@@ -766,7 +766,7 @@ bool QSerialPortPrivate::readNotification()
return true;
}
-bool QSerialPortPrivate::writeNotification(int maxSize)
+bool QSerialPortPrivate::writeNotification()
{
Q_Q(QSerialPort);
@@ -777,7 +777,7 @@ bool QSerialPortPrivate::writeNotification(int maxSize)
return false;
}
- int nextSize = qMin(writeBuffer.nextDataBlockSize(), maxSize);
+ int nextSize = writeBuffer.nextDataBlockSize();
const char *ptr = writeBuffer.readPointer();
diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h
index 7c2b771..dba0ac5 100644
--- a/src/serialport/qserialport_unix_p.h
+++ b/src/serialport/qserialport_unix_p.h
@@ -124,7 +124,7 @@ public:
bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
bool readNotification();
- bool writeNotification(int maxSize = INT_MAX);
+ bool writeNotification();
void exceptionNotification();
static QString portNameToSystemLocation(const QString &port);
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index f5bf080..e460c78 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -369,7 +369,7 @@ qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
::memcpy(ptr, data, maxSize);
if (!writeSequenceStarted)
- startAsyncWrite(WriteChunkSize);
+ startAsyncWrite();
return maxSize;
}
@@ -644,15 +644,13 @@ bool QSerialPortPrivate::startAsyncRead()
return true;
}
-bool QSerialPortPrivate::startAsyncWrite(int maxSize)
+bool QSerialPortPrivate::startAsyncWrite()
{
Q_Q(QSerialPort);
qint64 nextSize = writeBuffer.nextDataBlockSize();
const char *ptr = writeBuffer.readPointer();
- nextSize = qMin(nextSize, qint64(maxSize));
-
// no more data to write
if (!ptr || nextSize == 0)
return true;
@@ -760,7 +758,7 @@ void QSerialPortPrivate::completeAsyncWrite(DWORD numberOfBytes)
if (writeBuffer.isEmpty())
writeSequenceStarted = false;
else
- startAsyncWrite(WriteChunkSize);
+ startAsyncWrite();
}
bool QSerialPortPrivate::updateDcb()
diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h
index 5ae33ae..61e6ce8 100644
--- a/src/serialport/qserialport_win_p.h
+++ b/src/serialport/qserialport_win_p.h
@@ -101,12 +101,12 @@ public:
void _q_canCompleteWrite();
bool startAsyncRead();
- bool startAsyncWrite(int maxSize = INT_MAX);
+ bool startAsyncWrite();
void completeAsyncRead(DWORD numberOfBytes);
void completeAsyncWrite(DWORD numberOfBytes);
#else
bool notifyRead();
- bool notifyWrite(int maxSize = INT_MAX);
+ bool notifyWrite();
#endif
static QString portNameToSystemLocation(const QString &port);
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index 2983071..26ebf64 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -103,7 +103,7 @@ private slots:
if (EV_RXCHAR & eventMask)
dptr->notifyRead();
if (EV_TXEMPTY & eventMask)
- dptr->notifyWrite(QSerialPortPrivateData::WriteChunkSize);
+ dptr->notifyWrite();
}
private:
@@ -262,7 +262,7 @@ qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
::memcpy(ptr, data, maxSize);
// trigger write sequence
- notifyWrite(QSerialPortPrivateData::WriteChunkSize);
+ notifyWrite();
return maxSize;
}
@@ -291,7 +291,7 @@ bool QSerialPortPrivate::waitForReadyRead(int msec)
return true;
}
if (readyToWrite)
- notifyWrite(WriteChunkSize);
+ notifyWrite();
}
return false;
}
@@ -320,7 +320,7 @@ bool QSerialPortPrivate::waitForBytesWritten(int msec)
return false;
}
if (readyToWrite) {
- if (notifyWrite(WriteChunkSize))
+ if (notifyWrite())
return true;
}
}
@@ -382,11 +382,11 @@ bool QSerialPortPrivate::notifyRead()
return true;
}
-bool QSerialPortPrivate::notifyWrite(int maxSize)
+bool QSerialPortPrivate::notifyWrite()
{
Q_Q(QSerialPort);
- int nextSize = qMin(writeBuffer.nextDataBlockSize(), maxSize);
+ int nextSize = writeBuffer.nextDataBlockSize();
const char *ptr = writeBuffer.readPointer();