summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2001-12-22 01:53:27 +0000
committerPixel <Pixel>2001-12-22 01:53:27 +0000
commit1ab3f478e7333620e3f8d424d27bd86e54886a3f (patch)
tree795ba70046b47c94ecc86e363a9c0351f0a01285 /lib
parent07447744c6b3455c1703471b249bda89dba333f5 (diff)
Big bug in Write / CopyJob...
Diffstat (limited to 'lib')
-rw-r--r--lib/CopyJob.cc18
-rw-r--r--lib/Handle.cc3
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;