Skip to contentSkip to conversation

compress: compress_wait() must return error if timed out

PATCH Applied Richard Fitzgerald 2 participants 2 messages Oct 22, 2013 – Nov 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compress: compress_wait() must return error if timed out

The caller must be certain that a return of 0 really means that compress is ready for more data, so when poll() returns 0 for a timeout we must report that as an error.

---
 compress.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
compress.c +10 -8
index 5cd0966..d1a2283 100644
@@ -616,15 +616,17 @@ int compress_wait(struct compress *compress, int timeout_ms)
 	fds.events = POLLOUT | POLLIN;
 
 	ret = poll(&fds, 1, timeout_ms);
-	if (fds.revents & POLLERR) {
-		return oops(compress, EIO, "poll returned error!");
+	if (ret > 0) {
+		if (fds.revents & POLLERR)
+			return oops(compress, EIO, "poll returned error!");
+		if (fds.revents & (POLLOUT | POLLIN))
+			return 0;
 	}
-	/* A pause will cause -EBADFD or zero. */
-	if ((ret < 0) && (ret != -EBADFD))
+	if (ret == 0)
+		return oops(compress, ETIME, "poll timed out");
+	if (ret < 0)
 		return oops(compress, errno, "poll error");
-	if (fds.revents & (POLLOUT | POLLIN)) {
-		return 0;
-	}
-	return ret;
+
+	return oops(compress, EIO, "poll signalled unhandled event");
 }
 
Signature · 1 line
1.7.2.5
Applied
#1 lore raw
Quoted 3 lines · Richard Fitzgerald

The caller must be certain that a return of 0 really means that compress is ready for more data, so when poll() returns 0 for a timeout we must report that as an error.

Applied, thanks

--
~Vinod

Quoted 39 lines
---
 compress.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
compress.c +10 -8
index 5cd0966..d1a2283 100644
@@ -616,15 +616,17 @@ int compress_wait(struct compress *compress, int timeout_ms)
 	fds.events = POLLOUT | POLLIN;
 
 	ret = poll(&fds, 1, timeout_ms);
-	if (fds.revents & POLLERR) {
-		return oops(compress, EIO, "poll returned error!");
+	if (ret > 0) {
+		if (fds.revents & POLLERR)
+			return oops(compress, EIO, "poll returned error!");
+		if (fds.revents & (POLLOUT | POLLIN))
+			return 0;
 	}
-	/* A pause will cause -EBADFD or zero. */
-	if ((ret < 0) && (ret != -EBADFD))
+	if (ret == 0)
+		return oops(compress, ETIME, "poll timed out");
+	if (ret < 0)
 		return oops(compress, errno, "poll error");
-	if (fds.revents & (POLLOUT | POLLIN)) {
-		return 0;
-	}
-	return ret;
+
+	return oops(compress, EIO, "poll signalled unhandled event");
 }
 
Signature · 1 line
1.7.2.5