blob: e46e3dac94a9e09c4ac8b6557b79886fd669ba4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "CopyJob.h"
#include "General.h"
CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz) : s(as), d(ad), siz(asiz), cursiz(0), current(0) { }
CopyJob::~CopyJob() { }
int CopyJob::Do() throw (GeneralException) {
int r, 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;
}
cursiz += r;
}
}
String CopyJob::GetName() {
return (String("CopyJob from ") + s->GetName() + " to " + d->GetName());
}
|