diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CopyJob.cc | 2 | ||||
-rw-r--r-- | lib/Exceptions.cc | 8 | ||||
-rw-r--r-- | lib/Handle.cc | 11 | ||||
-rw-r--r-- | lib/Input.cc | 2 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/Output.cc | 2 | ||||
-rw-r--r-- | lib/Task.cc | 5 | ||||
-rw-r--r-- | lib/TaskMan.cc | 3 |
8 files changed, 19 insertions, 16 deletions
diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 04dff0b..6a35689 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -8,8 +8,6 @@ CopyJob::~CopyJob() { } int CopyJob::Do() { int r, tr; - cerr << "CopyJob running...\n"; - while (!s->IsClosed() || (siz != cursiz)) { if (!current) { tr = siz >= 0 ? siz - cursiz : COPY_BUFSIZ; diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index a4fca0f..9d2ba8e 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -38,7 +38,9 @@ IOGeneral::IOGeneral() { } IOAgain::IOAgain() : IOGeneral(_("No more bytes for reading or writing.")) { } -char * xstrdup(const char * s) throw (MemoryException) { +TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked environnement")) { } + +char * xstrdup(const char * s) throw (GeneralException) { char * r; if (!(r = ::strdup(s))) { @@ -48,7 +50,7 @@ char * xstrdup(const char * s) throw (MemoryException) { return r; } -void * xmalloc(ssize_t s) throw (MemoryException) { +void * xmalloc(ssize_t s) throw (GeneralException) { void * r; if (!(r = ::malloc(s))) { @@ -60,7 +62,7 @@ void * xmalloc(ssize_t s) throw (MemoryException) { return r; } -void * xrealloc(void * ptr, size_t s) throw (MemoryException) { +void * xrealloc(void * ptr, size_t s) throw (GeneralException) { void * r; if (!(r = ::realloc(ptr, s))) { diff --git a/lib/Handle.cc b/lib/Handle.cc index c1fbc8c..e5a23a3 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -20,7 +20,7 @@ int Handle::GetHandle() { return h; } -ssize_t Handle::write(const void *buf, size_t count) throw (IOGeneral) { +ssize_t Handle::write(const void *buf, size_t count) throw (GeneralException) { ssize_t r, tr = 0; bool done, full = false; @@ -40,7 +40,7 @@ ssize_t Handle::write(const void *buf, size_t count) throw (IOGeneral) { done = false; full = true; if (nonblock) { - throw IOAgain(); + throw TaskSwitch(); } else { sleep(1); } @@ -58,19 +58,16 @@ ssize_t Handle::write(const void *buf, size_t count) throw (IOGeneral) { return r + tr; } -ssize_t Handle::read(void *buf, size_t count) throw (IOGeneral) { +ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) { ssize_t r; errno = 0; if ((r = ::read(h, buf, count)) < 0) { - cerr << "read: throwing exception...\n"; 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. - cerr << "Throwing a 'again' exception.\n"; - throw IOAgain(); + throw TaskSwitch(); } else { - cerr << "Throwing an unknow exception.\n"; throw IOException(GetName(), IO_READ, count); } } diff --git a/lib/Input.cc b/lib/Input.cc index f4e2602..9ce7ca0 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -10,7 +10,7 @@ #include "Exceptions.h" #include "config.h" -Input::Input(String no) throw (IOGeneral) : +Input::Input(String no) throw (GeneralException) : Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : 0), n(no) { if (GetHandle() < 0) { diff --git a/lib/Makefile.am b/lib/Makefile.am index f5b1cfb..9778018 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,6 +8,6 @@ lib_LTLIBRARIES = libBaltisot.la libBaltisot_la_SOURCES = Exceptions.cc Handle.cc Output.cc String.cc\ Socket.cc Input.cc HttpServ.cc Variables.cc Action.cc Menu.cc Message.cc\ Form.cc Confirm.cc Table.cc checkargs.c datecalc.c IRC.cc Task.cc Buffer.cc\ - CopyJob.cc ReadJob.cc Regex.cc + CopyJob.cc ReadJob.cc Regex.cc TaskMan.cc libBaltisot_la_LDFLAGS = -release $(Baltisot_VERSION_INFO) diff --git a/lib/Output.cc b/lib/Output.cc index 75bb437..ab51c9f 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -10,7 +10,7 @@ #include "Exceptions.h" #include "config.h" -Output::Output(String no, int trunc = 1) throw (IOGeneral) : +Output::Output(String no, int trunc = 1) throw (GeneralException) : Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND)) : 1), n(no) { if (GetHandle() < 0) { diff --git a/lib/Task.cc b/lib/Task.cc index 27d2a24..faaeaf3 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -12,7 +12,10 @@ int Task::Do() { int Task::Run() { cerr << "Running task '" << GetName() << "'...\n"; try { - while ((state = Do()) != TASK_DONE); + state = Do(); + } + catch (TaskSwitch) { + throw; } catch (GeneralException e) { cerr << "Task " << GetName() << " caused an unexpected exception: '" << e.GetMsg() << "', closing it.\n"; diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc new file mode 100644 index 0000000..58c7eae --- /dev/null +++ b/lib/TaskMan.cc @@ -0,0 +1,3 @@ +#include <TaskMan.h> + +Task::Task() ( )
\ No newline at end of file |