summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Exceptions.cc30
-rw-r--r--lib/Handle.cc4
-rw-r--r--lib/ReadJob.cc8
-rw-r--r--lib/Task.cc7
4 files changed, 38 insertions, 11 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc
index 9d2ba8e..585b946 100644
--- a/lib/Exceptions.cc
+++ b/lib/Exceptions.cc
@@ -9,9 +9,21 @@
char GeneralException::t[BUFSIZ];
-GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { }
-GeneralException::GeneralException() : msg(0) { }
-GeneralException::GeneralException(const GeneralException & e) : msg(strdup(e.msg)) { }
+GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) {
+#ifdef DEBUG
+ cerr << "Generating a General Exception error: '" << msg << "'.\n";
+#endif
+}
+GeneralException::GeneralException() : msg(0) {
+#ifdef DEBUG
+ cerr << "Generating a General Exception error: '" << msg << "'.\n";
+#endif
+}
+GeneralException::GeneralException(const GeneralException & e) : msg(strdup(e.msg)) {
+#ifdef DEBUG
+ cerr << "Generating a General Exception error: '" << msg << "'.\n";
+#endif
+}
GeneralException::~GeneralException() {
free(msg);
@@ -36,9 +48,17 @@ IOGeneral::IOGeneral(String fn) : GeneralException(fn) { }
IOGeneral::IOGeneral() { }
-IOAgain::IOAgain() : IOGeneral(_("No more bytes for reading or writing.")) { }
+IOAgain::IOAgain() : IOGeneral(_("No more bytes for reading or writing.")) {
+#ifdef DEBUG
+ cerr << "Generating an IOAgain exception: '" << GetMsg() << "'.\n";
+#endif
+}
-TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked environnement")) { }
+TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked environnement")) {
+#ifdef DEBUG
+ cerr << "Generating a TaskSwitch exception: '" << GetMsg() << "'.\n";
+#endif
+}
char * xstrdup(const char * s) throw (GeneralException) {
char * r;
diff --git a/lib/Handle.cc b/lib/Handle.cc
index da9870f..7ad7cc6 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -40,7 +40,7 @@ ssize_t Handle::write(const void *buf, size_t count) throw (GeneralException) {
done = false;
full = true;
if (nonblock) {
- throw TaskSwitch();
+ throw IOAgain();
} else {
sleep(1);
}
@@ -66,7 +66,7 @@ ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) {
if ((!errno) || (errno = EAGAIN)) {
// Avant de déclarer une erreur, on vérifie si ce n'est pas un
// problème lié au fait qu'il n'y a plus d'octets.
- throw TaskSwitch();
+ throw IOAgain();
} else {
throw IOException(GetName(), IO_READ, count);
}
diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc
index 3bab150..a63eeca 100644
--- a/lib/ReadJob.cc
+++ b/lib/ReadJob.cc
@@ -13,23 +13,27 @@ int ReadJob::Do() {
while (!s->IsClosed()) {
if (!current) {
+ r = 0;
try {
cerr << "Trying to read...\n";
*s >> buff;
}
catch (IOAgain e) {
cerr << "Suspending ReadJob to wait for reading...\n";
- Suspend();
+ r = 1;
}
+ if (r) Suspend();
cerr << "Read some bytes...\n";
}
+ r = 0;
try {
*d << buff << endnl;
}
catch (IOAgain e) {
cerr << "Suspending ReadJob to wait for writing...\n";
- Suspend();
+ r = 1;
}
+ if (r) Suspend();
cerr << "Wrote some bytes...\n";
if (buff == "") return TASK_DONE;
}
diff --git a/lib/Task.cc b/lib/Task.cc
index 42147d3..c34d0e3 100644
--- a/lib/Task.cc
+++ b/lib/Task.cc
@@ -12,16 +12,19 @@ int Task::Do() {
int Task::Run() {
cerr << "Running task '" << GetName() << "'...\n";
try {
+ cerr << "Launching method Do()...\n";
state = Do();
}
catch (TaskSwitch) {
- Resume(1);
+ cerr << "Catch a task switching.\n";
throw;
}
catch (GeneralException e) {
cerr << "Task " << GetName() << " caused an unexpected exception: '" << e.GetMsg() << "', closing it.\n";
return TASK_DONE;
}
+
+ cerr << "Task exitted normally.\n";
return state;
}
@@ -49,8 +52,8 @@ int Task::Suspend() throw (GeneralException) {
}
void Task::Resume(int val) throw (GeneralException) {
+ cerr << "Resuming task " << GetName() << "...\n";
if (suspended) {
- cerr << "Resuming task " << GetName() << "...\n";
suspended = false;
longjmp(env, val);
} else {