summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-11-04 20:18:14 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-11-04 20:18:14 +0100
commit4159ee840549df11287294f0928e90f35f3e06ff (patch)
tree4a3947e37d54bdb78b4042e9ced20dbf181b5a2c /src/corelib/io
parent59dbf1786f22ec4ac88d8f9d38cac5cfb82acaea (diff)
parentc8c39ecc37c156ac2677de09a26548dfc274b564 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: config.tests/unix/ptrsize.test configure src/corelib/global/qnamespace.h src/network/socket/qabstractsocket.cpp tests/auto/other/networkselftest/networkselftest.pro Change-Id: Ic78abb4a34f9068567cea876861d4220f5a07672
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qiodevice.cpp7
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp10
-rw-r--r--src/corelib/io/qwindowspipereader.cpp4
-rw-r--r--src/corelib/io/qwinoverlappedionotifier.cpp62
4 files changed, 63 insertions, 20 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index fa91b17747..ce6225266a 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -1289,6 +1289,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize)
const char *startOfBlock = data;
qint64 writtenSoFar = 0;
+ const qint64 savedPos = d->pos;
forever {
const char *endOfBlock = startOfBlock;
@@ -1300,7 +1301,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize)
qint64 ret = writeData(startOfBlock, blockSize);
if (ret <= 0) {
if (writtenSoFar && !sequential)
- d->buffer.skip(writtenSoFar);
+ d->buffer.skip(d->pos - savedPos);
return writtenSoFar ? writtenSoFar : ret;
}
if (!sequential) {
@@ -1316,7 +1317,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize)
qint64 ret = writeData("\r\n", 2);
if (ret <= 0) {
if (writtenSoFar && !sequential)
- d->buffer.skip(writtenSoFar);
+ d->buffer.skip(d->pos - savedPos);
return writtenSoFar ? writtenSoFar : ret;
}
if (!sequential) {
@@ -1329,7 +1330,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize)
}
if (writtenSoFar && !sequential)
- d->buffer.skip(writtenSoFar);
+ d->buffer.skip(d->pos - savedPos);
return writtenSoFar;
}
#endif
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 262703b9e6..e365d8d7e6 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -68,8 +68,8 @@
#if defined(Q_OS_BSD4)
# if defined(Q_OS_NETBSD)
- define QT_STATFSBUF struct statvfs
- define QT_STATFS ::statvfs
+# define QT_STATFSBUF struct statvfs
+# define QT_STATFS ::statvfs
# else
# define QT_STATFSBUF struct statfs
# define QT_STATFS ::statfs
@@ -507,9 +507,15 @@ void QStorageInfoPrivate::retrieveVolumeInfo()
valid = true;
ready = true;
+#if defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD)
+ bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize;
+ bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize;
+ bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_bsize;
+#else
bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize;
bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize;
bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize;
+#endif
blockSize = statfs_buf.f_bsize;
#if defined(Q_OS_ANDROID) || defined (Q_OS_BSD4)
#if defined(_STATFS_F_FLAGS)
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index a49fcdaf9f..f0d6417483 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -186,6 +186,10 @@ void QWindowsPipeReader::notified(quint32 numberOfBytesRead, quint32 errorCode,
case ERROR_PIPE_NOT_CONNECTED:
pipeBroken = true;
break;
+ case ERROR_OPERATION_ABORTED:
+ if (stopped)
+ break;
+ // fall through
default:
emit winError(errorCode, QLatin1String("QWindowsPipeReader::notified"));
pipeBroken = true;
diff --git a/src/corelib/io/qwinoverlappedionotifier.cpp b/src/corelib/io/qwinoverlappedionotifier.cpp
index 083feb4a20..c6ce15c2c9 100644
--- a/src/corelib/io/qwinoverlappedionotifier.cpp
+++ b/src/corelib/io/qwinoverlappedionotifier.cpp
@@ -33,6 +33,7 @@
#include "qwinoverlappedionotifier_p.h"
#include <qdebug.h>
+#include <qatomic.h>
#include <qelapsedtimer.h>
#include <qmutex.h>
#include <qpointer.h>
@@ -99,6 +100,7 @@ public:
{
}
+ OVERLAPPED *waitForAnyNotified(int msecs);
void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped);
OVERLAPPED *_q_notified();
@@ -108,6 +110,7 @@ public:
HANDLE hHandle;
HANDLE hSemaphore;
HANDLE hResultsMutex;
+ QAtomicInt waiting;
QQueue<IOResult> results;
};
@@ -286,28 +289,21 @@ void QWinOverlappedIoNotifier::setEnabled(bool enabled)
d->iocp->unregisterNotifier(d);
}
-/*!
- * Wait synchronously for any notified signal.
- *
- * The function returns a pointer to the OVERLAPPED object corresponding to the completed I/O
- * operation. In case no I/O operation was completed during the \a msec timeout, this function
- * returns a null pointer.
- */
-OVERLAPPED *QWinOverlappedIoNotifier::waitForAnyNotified(int msecs)
+OVERLAPPED *QWinOverlappedIoNotifierPrivate::waitForAnyNotified(int msecs)
{
- Q_D(QWinOverlappedIoNotifier);
- if (!d->iocp->isRunning()) {
+ if (!iocp->isRunning()) {
qWarning("Called QWinOverlappedIoNotifier::waitForAnyNotified on inactive notifier.");
return 0;
}
if (msecs == 0)
- d->iocp->drainQueue();
+ iocp->drainQueue();
- switch (WaitForSingleObject(d->hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs))) {
+ const DWORD wfso = WaitForSingleObject(hSemaphore, msecs == -1 ? INFINITE : DWORD(msecs));
+ switch (wfso) {
case WAIT_OBJECT_0:
- ReleaseSemaphore(d->hSemaphore, 1, NULL);
- return d->_q_notified();
+ ReleaseSemaphore(hSemaphore, 1, NULL);
+ return _q_notified();
case WAIT_TIMEOUT:
return 0;
default:
@@ -316,6 +312,39 @@ OVERLAPPED *QWinOverlappedIoNotifier::waitForAnyNotified(int msecs)
}
}
+class QScopedAtomicIntIncrementor
+{
+public:
+ QScopedAtomicIntIncrementor(QAtomicInt &i)
+ : m_int(i)
+ {
+ ++m_int;
+ }
+
+ ~QScopedAtomicIntIncrementor()
+ {
+ --m_int;
+ }
+
+private:
+ QAtomicInt &m_int;
+};
+
+/*!
+ * Wait synchronously for any notified signal.
+ *
+ * The function returns a pointer to the OVERLAPPED object corresponding to the completed I/O
+ * operation. In case no I/O operation was completed during the \a msec timeout, this function
+ * returns a null pointer.
+ */
+OVERLAPPED *QWinOverlappedIoNotifier::waitForAnyNotified(int msecs)
+{
+ Q_D(QWinOverlappedIoNotifier);
+ QScopedAtomicIntIncrementor saii(d->waiting);
+ OVERLAPPED *result = d->waitForAnyNotified(msecs);
+ return result;
+}
+
/*!
* Wait synchronously for the notified signal.
*
@@ -324,6 +353,8 @@ OVERLAPPED *QWinOverlappedIoNotifier::waitForAnyNotified(int msecs)
*/
bool QWinOverlappedIoNotifier::waitForNotified(int msecs, OVERLAPPED *overlapped)
{
+ Q_D(QWinOverlappedIoNotifier);
+ QScopedAtomicIntIncrementor saii(d->waiting);
int t = msecs;
QElapsedTimer stopWatch;
stopWatch.start();
@@ -350,7 +381,8 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod
results.enqueue(IOResult(numberOfBytes, errorCode, overlapped));
ReleaseMutex(hResultsMutex);
ReleaseSemaphore(hSemaphore, 1, NULL);
- emit q->_q_notify();
+ if (!waiting)
+ emit q->_q_notify();
}
OVERLAPPED *QWinOverlappedIoNotifierPrivate::_q_notified()