From 3f720784d55707024fff675a5238fde0168d1a40 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 15 Nov 2001 14:52:43 +0000 Subject: More work into TaskMan... --- lib/CopyJob.cc | 56 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'lib/CopyJob.cc') diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index fb8c6e2..9dc9978 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -1,34 +1,46 @@ #include "CopyJob.h" #include "General.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz) : s(as), d(ad), siz(asiz), cursiz(0) { } +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), siz(asiz), ds(ads), cursiz(0), r(0) { + WaitFor(s); + WaitFor(d); +} CopyJob::~CopyJob() { } int CopyJob::Do() throw (GeneralException) { - int r, tr; + int tr; - while (!s->IsClosed() || (siz != cursiz)) { - switch (current) { - case 0: - tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; - try { - r = s->read(buffer, MIN(COPY_BUFSIZ, tr)); - } - catch (IOAgain e) { - throw TaskSwitch(); - } - case 1: - try { - d->write(buffer, r); - } - catch (IOAgain e) { - current = 1; - throw TaskSwitch(); - } - current = 0; + switch (current) { + case 0: + tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; + try { + r = s->read(buffer, MIN(COPY_BUFSIZ, tr)); + } + catch (IOAgain e) { + Suspend(); + } + case 1: + if (!r) { + return TASK_DONE; + } + try { + d->write(buffer, r); + } + catch (IOAgain e) { + current = 1; + Suspend(); } - cursiz += r; + current = 0; + } + cursiz += r; + + if (!s->IsClosed() || (siz != cursiz)) { + throw TaskSwitch(); + } + + if (ds) { + delete s; } return TASK_DONE; -- cgit v1.2.3