summaryrefslogtreecommitdiff
path: root/lib/ReadJob.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ReadJob.cc')
-rw-r--r--lib/ReadJob.cc33
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc
index a63eeca..2c244ad 100644
--- a/lib/ReadJob.cc
+++ b/lib/ReadJob.cc
@@ -5,37 +5,36 @@ ReadJob::ReadJob(Handle * as, Handle * ad) : s(as), d(ad), current(0) { }
ReadJob::~ReadJob() { }
-int ReadJob::Do() {
- int r;
+int ReadJob::Do() throw (GeneralException) {
String buff;
cerr << "ReadJob running...\n";
while (!s->IsClosed()) {
- if (!current) {
- r = 0;
+ switch (current) {
+ case 0:
try {
cerr << "Trying to read...\n";
*s >> buff;
}
catch (IOAgain e) {
cerr << "Suspending ReadJob to wait for reading...\n";
- r = 1;
+ throw TaskSwitch();
}
- if (r) Suspend();
cerr << "Read some bytes...\n";
+ case 1:
+ try {
+ *d << buff << endnl;
+ }
+ catch (IOAgain e) {
+ cerr << "Suspending ReadJob to wait for writing...\n";
+ current = 1;
+ throw TaskSwitch();
+ }
+ current = 0;
+ cerr << "Wrote some bytes...\n";
+ if (buff == "") return TASK_DONE;
}
- r = 0;
- try {
- *d << buff << endnl;
- }
- catch (IOAgain e) {
- cerr << "Suspending ReadJob to wait for writing...\n";
- r = 1;
- }
- if (r) Suspend();
- cerr << "Wrote some bytes...\n";
- if (buff == "") return TASK_DONE;
}
return TASK_DONE;