diff options
Diffstat (limited to 'lib/CopyJob.cc')
-rw-r--r-- | lib/CopyJob.cc | 56 |
1 files changed, 34 insertions, 22 deletions
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; |