From 27d3e39b6b38d81508ece1b12acfb0296aaef99d Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 3 Oct 2017 19:38:00 +0200 Subject: [PATCH] io-job: generic async IO copy job wrapper --- meson.build | 2 +- src/mconnect/{transfer.vala => io-job.vala} | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) rename src/mconnect/{transfer.vala => io-job.vala} (80%) diff --git a/meson.build b/meson.build index 514e9e7..579ce35 100644 --- a/meson.build +++ b/meson.build @@ -47,7 +47,7 @@ mconnect_src = [ 'src/mconnect/utils.vala', 'src/mconnect/property-proxy.vala', 'src/mconnect/share.vala', - 'src/mconnect/transfer.vala', + 'src/mconnect/io-job.vala', 'src/mconnect/transfer-download.vala', 'src/mconnect/logging.vala', 'src/crypt/certificate.vala', diff --git a/src/mconnect/transfer.vala b/src/mconnect/io-job.vala similarity index 80% rename from src/mconnect/transfer.vala rename to src/mconnect/io-job.vala index 5e8bedc..c8059c8 100644 --- a/src/mconnect/transfer.vala +++ b/src/mconnect/io-job.vala @@ -15,13 +15,14 @@ * AUTHORS * Maciek Borzecki */ +using Logging; -class Transfer : Object { +class IOCopyJob : Object { private InputStream from = null; private OutputStream to = null; - public Transfer(InputStream from, OutputStream to) { + public IOCopyJob(InputStream from, OutputStream to) { this.from = from; this.to = to; } @@ -34,17 +35,20 @@ class Transfer : Object { * * @return number of bytes transferred if no error occurred */ - public async uint64 transfer_async(Cancellable? cancel) throws Error { + public async uint64 start_async(Cancellable? cancel) throws Error { uint64 bytes_done = 0; var chunk_size = 4096; var max_chunk_size = 64 * 1024; while (true) { - var data = yield this.from.read_bytes_async(chunk_size); - debug("read %d bytes", data.length); + var data = yield this.from.read_bytes_async(chunk_size, + Priority.DEFAULT, + cancel); + vdebug("read %d bytes", data.length); if (data.length == 0) { break; } - yield this.to.write_bytes_async(data); + yield this.to.write_bytes_async(data, Priority.DEFAULT, + cancel); bytes_done += data.length; this.progress(bytes_done);