diff options
author | Pixel <Pixel> | 2001-11-23 11:26:50 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-23 11:26:50 +0000 |
commit | 1311938cc52369b8631c29f83a9ecdf4a5f12f19 (patch) | |
tree | 4ec27df25d3df977631e62a82c11fd387a28b8c2 /lib | |
parent | 0497d21e5b7b483259642aad1f23392995863c17 (diff) |
Last modifications...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Buffer.cc | 2 | ||||
-rw-r--r-- | lib/CopyJob.cc | 2 | ||||
-rw-r--r-- | lib/Handle.cc | 2 | ||||
-rw-r--r-- | lib/HttpServ.cc | 10 | ||||
-rw-r--r-- | lib/Socket.cc | 2 | ||||
-rw-r--r-- | lib/String.cc | 2 | ||||
-rw-r--r-- | lib/Task.cc | 34 | ||||
-rw-r--r-- | lib/TaskMan.cc | 75 |
8 files changed, 78 insertions, 51 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 123cc65..b3cb10b 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -65,6 +65,6 @@ Buffer Buffer::operator=(const Buffer & b) { } else { buffer = 0; } - return *this; } + return *this; } diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 55fe59d..3b01092 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -1,7 +1,7 @@ #include "CopyJob.h" #include "General.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), siz(asiz), ds(ads), cursiz(0), r(0) { +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), ds(ads), siz(asiz), cursiz(0), r(0) { WaitFor(s, W4_STICKY); WaitFor(d, W4_STICKY); } diff --git a/lib/Handle.cc b/lib/Handle.cc index 6f7c6e5..30ad7ef 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -120,7 +120,7 @@ Handle & operator>>(Handle & h, String & s) { } t[i] = '\0'; - s.set("%s", t); + s = t; return h; } diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index cda572d..c534741 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -361,13 +361,17 @@ String ProcessRequest::GetMime(const String & f) { HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) : p(ap), name(nname), localport(port) { bool r = true; + cerr << "Initialising Mini HTTP-Server on port " << localport << endl; + r = Listener.SetLocal("", port); - if (r) { - r = Listener.Listen(); + if (!r) { + throw GeneralException("Initialisation of the Mini HTTP-Server failed: can't bind"); } + r = Listener.Listen(); + if (!r) { - throw GeneralException("Initialisation of the Mini HTTP-Server failed."); + throw GeneralException("Initialisation of the Mini HTTP-Server failed: can't listen"); } Listener.SetNonBlock(); diff --git a/lib/Socket.cc b/lib/Socket.cc index 5d80783..d3d7c19 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -104,7 +104,7 @@ bool Socket::Connect(String host, int port) { bool Socket::Listen(void) { if (!listening && !connected) { - if (listen(GetHandle(), 10)) { + if (!listen(GetHandle(), 10)) { listening = true; } } diff --git a/lib/String.cc b/lib/String.cc index d64f065..d587b75 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -51,7 +51,7 @@ const char * String::set(char * s, ...) { va_list ap; va_start(ap, s); - vsprintf(t, s, ap); + vsnprintf(t, BUFSIZ, s, ap); free(str); str = ::strdup(t); va_end(ap); diff --git a/lib/Task.cc b/lib/Task.cc index a56a2ff..b54402f 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -4,11 +4,11 @@ #include "Task.h" #include "String.h" -Task::Task() : state(TASK_ON_HOLD), suspended(false), cleanup(false), current(0) { +Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), cleanup(false), suspended(false) { TaskMan::AddTask(this); } + Task::~Task() { - TaskMan::RemoveTask(this); } int Task::Do() throw (GeneralException) { @@ -23,7 +23,7 @@ int Task::Run() { } catch (TaskSwitch) { cerr << "Catch a task switching.\n"; - throw; + return state; } catch (GeneralException e) { cerr << "Task " << GetName() << " caused an unexpected exception: '" << e.GetMsg() << "', closing it.\n"; @@ -53,18 +53,38 @@ void Task::WaitFor(Handle * h, int flags) { w4ha.push_back(w4ha_t(h, flags)); } -void Task::WaitFor(Task * t, int flags) { - w4ta.push_back(w4ta_t(t, flags)); +void Task::WaitFor(Task * t) { + t->wbta.push_back(wbta_t(this)); } -void Task::WaitFor(pid_t p, int flags) { - w4pr.push_back(w4pr_t(p, flags)); +void Task::WaitFor(pid_t p) { + w4pr.push_back(w4pr_t(p)); } void Task::WaitFor(timeval t, int flags) { w4to.push_back(w4to_t(t, flags)); } +bool Task::WaitingFor(Handle * ha) { + vector<w4ha_t>::iterator p; + + for (p = w4ha.begin(); p && (p != w4ha.end()); p++) { + if (p->ha == ha) return true; + } + + return false; +} + +bool Task::WaitingFor(pid_t pr) { + vector<w4pr_t>::iterator p; + + for (p = w4pr.begin(); p && (p != w4pr.end()); p++) { + if (p->pr == pr) return true; + } + + return false; +} + void Task::SetBurst() { state = TASK_BURST; } diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index ded359a..1af9234 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -4,6 +4,7 @@ #include "TaskMan.h" vector<Task *> TaskMan::TaskList; +vector<Task *> TaskMan::Zombies; int TaskMan::number = 0; bool TaskMan::inited = false; @@ -30,59 +31,61 @@ void TaskMan::Init() throw (GeneralException) { } int TaskMan::AddTask(Task * t) { + if (!inited) { + Init(); + } TaskList.push_back(t); number++; return 0; } -int TaskMan::RemoveTask(Task * t) { - int i; +void TaskMan::MainLoop() throw (GeneralException) { + TaskList_t::iterator p; + Task * t; - for (i = 0; i < number; i++) { - if (TaskList[i] == t) { - TaskList.erase(&TaskList[i]); - number--; - return 0; - } + int no_burst; + + if (!inited) { + Init(); } - return -1; -} - -void TaskMan::MainLoop() throw (GeneralException) { - Task ** p, * t; while (1) { + cerr << "TaskMan: Begin of main loop with " << number << " task to handle.\n"; + if (number == 0) { throw GeneralException("TaskMan: No more task to manage."); } - p = TaskList.begin(); - - while (1) { - t = *p; - -#ifdef HAVE_POLL -#else -#endif + no_burst = 0; + while (!no_burst) { + no_burst = 1; + /* First, we will check for any burning task and run 'em */ + for (p = TaskList.begin(); p && (p != TaskList.end()); p++) { + t = *p; - try { - t->Run(); - } - catch (TaskSwitch) { - continue; - } - if (t->GetState() == TASK_DONE) { - TaskList.erase(p); - } + if (t->GetState() == TASK_BURST) { + t->Run(); + } - if (p == TaskList.end()) { - break; + if (t->GetState() == TASK_BURST) { + no_burst = 0; + } else if (t->GetState() == TASK_DONE) { + TaskList.erase(p); + number--; + p--; + if (t->HasToClean()) { + delete t; + } else { + Zombies.push_back(t); + } + } } - - p++; } - - } + +#ifdef HAVE_POLL +#else +#endif + } |