diff options
Diffstat (limited to 'lib/CopyJob.cc')
-rw-r--r-- | lib/CopyJob.cc | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 7dccbc5..73864bb 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -1,15 +1,38 @@ #include "CopyJob.h" +#include "General.h" -CopyJob::CopyJob(Handle & as, Handle & ad) : s(as), d(ad) { } +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz) : s(as), d(ad), siz(asiz), cursiz(0), current(0) { } CopyJob::~CopyJob() { } int CopyJob::Do() { - int r; - char buffer[4096]; + int r, tr; - while (!s.IsClosed()) { - r = s.read(buffer, 4096); - d.write(buffer, r); + cerr << "CopyJob running...\n"; + + while (!s->IsClosed() || (siz != cursiz)) { + if (!current) { + tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; + try { + r = s->read(buffer, MIN(COPY_BUFSIZ, tr)); + } + catch (IOAgain) { + return TASK_WAITING_HANDLE; + } + current = 0; + } + try { + d->write(buffer, r); + } + catch (IOAgain) { + current = 1; + return TASK_WAITING_HANDLE; + } + cursiz += r; } } + +String CopyJob::GetName() { + return (String("CopyJob from ") + s->GetName() + " to " + d->GetName()); +} + |