diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CopyJob.cc | 18 | ||||
-rw-r--r-- | lib/Handle.cc | 3 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 524a52c..7acc7c5 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -2,7 +2,7 @@ #include "General.h" #include "config.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0) { +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0), w(0), tw(0) { s->SetNonBlock(); d->SetNonBlock(); WaitFor(s, W4_READING); @@ -26,9 +26,7 @@ int CopyJob::Do() throw (GeneralException) { tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; try { r = s->read(buffer, MIN(COPY_BUFSIZ, tr)); -// cerr << "CopyJob: read " << r << " bytes: " << endl; -// buffer[r] = 0; -// cerr << buffer << endl; +// cerr << "CopyJob: read " << r << " bytes." << endl; } catch (IOAgain e) { WaitFor(s, W4_READING); @@ -37,12 +35,20 @@ int CopyJob::Do() throw (GeneralException) { if (!r) { return TASK_DONE; } + tw = 0; case 1: + current = 1; try { - d->write(buffer, r); + w = d->write(buffer + tw, r - tw); } catch (IOAgain e) { - current = 1; + WaitFor(d, W4_WRITING); + Suspend(TASK_ON_HOLD); + } +// cerr << "CopyJob: wrote " << w << " bytes." << endl; + tw += w; + if (r != tw) { +// cerr << "CopyJob: We did expect to write a total of " << r << " bytes and we achieved " << tw << " bytes so far.\n"; WaitFor(d, W4_WRITING); Suspend(TASK_ON_HOLD); } diff --git a/lib/Handle.cc b/lib/Handle.cc index e98b2c7..9f6736d 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -56,6 +56,9 @@ ssize_t Handle::write(const void *buf, size_t count) throw (GeneralException) { throw IOException(GetName(), IO_WRITE, count); } } else if (((size_t) r) != count) { + if (nonblock) { + return r; + } full = done = false; ((char *)buf) += r; tr += r; |