#include "CopyJob.h" #include "General.h" CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), ds(ads), siz(asiz), cursiz(0), r(0) { s->SetNonBlock(); d->SetNonBlock(); WaitFor(s, W4_READING); } CopyJob::~CopyJob() { } int CopyJob::Do() throw (GeneralException) { int tr; switch (current) { case 0: tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; try { r = s->read(buffer, MIN(COPY_BUFSIZ, tr)); } catch (IOAgain e) { WaitFor(s, W4_READING); Suspend(TASK_ON_HOLD); } if (!r) { return TASK_DONE; } case 1: try { d->write(buffer, r); } catch (IOAgain e) { current = 1; WaitFor(d, W4_WRITING); Suspend(TASK_ON_HOLD); } current = 0; } cursiz += r; if (!s->IsClosed() && (siz != cursiz)) { WaitFor(s, W4_READING); Suspend(TASK_ON_HOLD); } if (ds) { delete s; } return TASK_DONE; } String CopyJob::GetName() { return (String("CopyJob from ") + s->GetName() + " to " + d->GetName()); }