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>
This commit is contained in:
David Edmundson 2019-07-23 08:44:46 +02:00
parent f8e2c2fb47
commit 97c1e5337e

View File

@ -170,24 +170,27 @@ int QWaylandMimeData::readData(int fd, QByteArray &data) const
timeout.tv_sec = 1; timeout.tv_sec = 1;
timeout.tv_usec = 0; timeout.tv_usec = 0;
int ready = select(FD_SETSIZE, &readset, nullptr, nullptr, &timeout); Q_FOREVER {
if (ready < 0) { int ready = select(FD_SETSIZE, &readset, nullptr, nullptr, &timeout);
qWarning() << "QWaylandDataOffer: select() failed"; if (ready < 0) {
return -1; qWarning() << "QWaylandDataOffer: select() failed";
} else if (ready == 0) { return -1;
qWarning("QWaylandDataOffer: timeout reading from pipe"); } else if (ready == 0) {
return -1; qWarning("QWaylandDataOffer: timeout reading from pipe");
} else { return -1;
char buf[4096]; } else {
int n = QT_READ(fd, buf, sizeof buf); char buf[4096];
int n = QT_READ(fd, buf, sizeof buf);
if (n > 0) { if (n < 0) {
data.append(buf, n); qWarning("QWaylandDataOffer: read() failed");
n = readData(fd, data); return -1;
} else if (n < 0) { } else if (n == 0) {
qWarning("QWaylandDataOffer: read() failed"); return 0;
} else if (n > 0) {
data.append(buf, n);
}
} }
return n;
} }
} }