65 lines
2.2 KiB
Diff
65 lines
2.2 KiB
Diff
|
From 80bf946e78b5b5b4276668249eb1fab769259426 Mon Sep 17 00:00:00 2001
|
||
|
From: David Edmundson <davidedmundson@kde.org>
|
||
|
Date: Tue, 23 Jul 2019 08:44:46 +0200
|
||
|
Subject: [PATCH] Client: Remove recursion in data offer retrieval
|
||
|
|
||
|
A loop functions just as well is more readable and uses less stack
|
||
|
memory.
|
||
|
|
||
|
Change-Id: I6f6c6b7b8047c42080fb8b9e0bc3eae96f8872ab
|
||
|
Reviewed-by: David Faure <david.faure@kdab.com>
|
||
|
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
|
||
|
---
|
||
|
src/client/qwaylanddataoffer.cpp | 37 +++++++++++++++++---------------
|
||
|
1 file changed, 20 insertions(+), 17 deletions(-)
|
||
|
|
||
|
diff --git a/src/client/qwaylanddataoffer.cpp b/src/client/qwaylanddataoffer.cpp
|
||
|
index 4c06277f..2297e8a1 100644
|
||
|
--- a/src/client/qwaylanddataoffer.cpp
|
||
|
+++ b/src/client/qwaylanddataoffer.cpp
|
||
|
@@ -170,24 +170,27 @@ int QWaylandMimeData::readData(int fd, QByteArray &data) const
|
||
|
timeout.tv_sec = 1;
|
||
|
timeout.tv_usec = 0;
|
||
|
|
||
|
- int ready = select(FD_SETSIZE, &readset, nullptr, nullptr, &timeout);
|
||
|
- if (ready < 0) {
|
||
|
- qWarning() << "QWaylandDataOffer: select() failed";
|
||
|
- return -1;
|
||
|
- } else if (ready == 0) {
|
||
|
- qWarning("QWaylandDataOffer: timeout reading from pipe");
|
||
|
- return -1;
|
||
|
- } else {
|
||
|
- char buf[4096];
|
||
|
- int n = QT_READ(fd, buf, sizeof buf);
|
||
|
-
|
||
|
- if (n > 0) {
|
||
|
- data.append(buf, n);
|
||
|
- n = readData(fd, data);
|
||
|
- } else if (n < 0) {
|
||
|
- qWarning("QWaylandDataOffer: read() failed");
|
||
|
+ Q_FOREVER {
|
||
|
+ int ready = select(FD_SETSIZE, &readset, nullptr, nullptr, &timeout);
|
||
|
+ if (ready < 0) {
|
||
|
+ qWarning() << "QWaylandDataOffer: select() failed";
|
||
|
+ return -1;
|
||
|
+ } else if (ready == 0) {
|
||
|
+ qWarning("QWaylandDataOffer: timeout reading from pipe");
|
||
|
+ return -1;
|
||
|
+ } else {
|
||
|
+ char buf[4096];
|
||
|
+ int n = QT_READ(fd, buf, sizeof buf);
|
||
|
+
|
||
|
+ if (n < 0) {
|
||
|
+ qWarning("QWaylandDataOffer: read() failed");
|
||
|
+ return -1;
|
||
|
+ } else if (n == 0) {
|
||
|
+ return 0;
|
||
|
+ } else if (n > 0) {
|
||
|
+ data.append(buf, n);
|
||
|
+ }
|
||
|
}
|
||
|
- return n;
|
||
|
}
|
||
|
}
|
||
|
|