aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2022-11-04 15:29:18 -0600
committerMarvin W <git@larma.de>2022-11-04 15:45:48 -0600
commite62955d3cf266a7f7ff0f2085a64f1c99021127c (patch)
treea376d6f6c8f7d040635ee213d031789177e1b3af /plugins
parent6e37f3fe3fa0f4ce9a25a91e9d97191c8e4abec1 (diff)
downloaddino-e62955d3cf266a7f7ff0f2085a64f1c99021127c.tar.gz
dino-e62955d3cf266a7f7ff0f2085a64f1c99021127c.zip
HTTP: Make LimitInputStream pollable for better async compatibility
Fixes #1307
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http-files/src/file_provider.vala21
1 files changed, 20 insertions, 1 deletions
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 7928dc81..1433a74f 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -46,7 +46,7 @@ public class FileProvider : Dino.FileProvider, Object {
}
}
- private class LimitInputStream : InputStream {
+ private class LimitInputStream : InputStream, PollableInputStream {
InputStream inner;
int64 remaining_size;
@@ -55,6 +55,20 @@ public class FileProvider : Dino.FileProvider, Object {
this.remaining_size = max_size;
}
+ public bool can_poll() {
+ return inner is PollableInputStream && ((PollableInputStream)inner).can_poll();
+ }
+
+ public PollableSource create_source(Cancellable? cancellable = null) {
+ if (!can_poll()) throw new IOError.NOT_SUPPORTED("Stream is not pollable");
+ return ((PollableInputStream)inner).create_source(cancellable);
+ }
+
+ public bool is_readable() {
+ if (!can_poll()) throw new IOError.NOT_SUPPORTED("Stream is not pollable");
+ return ((PollableInputStream)inner).is_readable();
+ }
+
private ssize_t check_limit(ssize_t read) throws IOError {
this.remaining_size -= read;
if (remaining_size < 0) throw new IOError.FAILED("Stream length exceeded limit");
@@ -69,6 +83,11 @@ public class FileProvider : Dino.FileProvider, Object {
return check_limit(yield inner.read_async(buffer, io_priority, cancellable));
}
+ public ssize_t read_nonblocking_fn(uint8[] buffer) throws Error {
+ if (!is_readable()) throw new IOError.WOULD_BLOCK("Stream is not readable");
+ return read(buffer);
+ }
+
public override bool close(Cancellable? cancellable = null) throws IOError {
return inner.close(cancellable);
}