diff options
author | Pixel <Pixel> | 2001-11-15 14:52:43 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-15 14:52:43 +0000 |
commit | 3f720784d55707024fff675a5238fde0168d1a40 (patch) | |
tree | 84a5b9843ede69aaf76cd9b791686b2a3ea7c3d7 /lib/CopyJob.cc | |
parent | 8694409f2a5531e9f3263e8a42248a3ca91ac14f (diff) |
More work into TaskMan...
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; |