diff options
-rw-r--r-- | include/Task.h | 3 | ||||
-rw-r--r-- | include/TaskMan.h | 4 | ||||
-rw-r--r-- | lib/HttpServ.cc | 6 | ||||
-rw-r--r-- | lib/Task.cc | 10 | ||||
-rw-r--r-- | lib/TaskMan.cc | 57 |
5 files changed, 38 insertions, 42 deletions
diff --git a/include/Task.h b/include/Task.h index f80258d..e7ad1c9 100644 --- a/include/Task.h +++ b/include/Task.h @@ -30,8 +30,6 @@ class Task : public Base { void WaitFor(timeval, int = 0); Task * WaitedBy(); void SetBurst(); - void SetCleanUp(); - bool HasToClean(); void Stop(); void Restart(); bool IsStopped(); @@ -49,7 +47,6 @@ class Task : public Base { int state; bool stopped; - bool cleanup; bool suspended; Task * wbta; }; diff --git a/include/TaskMan.h b/include/TaskMan.h index 03c0681..650a521 100644 --- a/include/TaskMan.h +++ b/include/TaskMan.h @@ -15,6 +15,7 @@ class TaskMan : public Base { static void WaitFor(Handle *, Task *, int = 0); static void WaitFor(pid_t, Task *); static void WaitFor(timeval, Task *, int = 0); + static int GotChild(pid_t, int); class w4ha_t { public: @@ -26,8 +27,9 @@ class TaskMan : public Base { class w4pr_t { public: - w4pr_t(pid_t apr, Task * aT) : pr(apr), T(aT) { } + w4pr_t(pid_t apr, Task * aT) : pr(apr), flag(0), status(0), T(aT) { } pid_t pr; + int flag, status; Task * T; }; diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 75b6800..602ebe0 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -37,7 +37,9 @@ class ProcessRequest : public Task { bool bad, hasvars, post; }; -ProcessRequest::ProcessRequest(Action * ap, const Socket & as, const String & aname, int aport) : localport(aport), p(ap), s(as), name(aname) { } +ProcessRequest::ProcessRequest(Action * ap, const Socket & as, const String & aname, int aport) : localport(aport), p(ap), s(as), name(aname) { + SetBurst(); +} String ProcessRequest::GetName() { return "Processing HTTP request"; @@ -420,8 +422,6 @@ int HttpServ::Do() { Socket s = Listener.Accept(); s.SetNonBlock(); r = new ProcessRequest(p, s, name, localport); - r->SetBurst(); - r->SetCleanUp(); } catch (GeneralException) { } diff --git a/lib/Task.cc b/lib/Task.cc index 60a9872..bc7c7a0 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -4,7 +4,7 @@ #include "Task.h" #include "String.h" -Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), cleanup(false), suspended(false), wbta(0) { +Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), suspended(false), wbta(0) { TaskMan::AddTask(this); } @@ -70,14 +70,6 @@ void Task::SetBurst() { state = TASK_BURST; } -void Task::SetCleanUp() { - cleanup = true; -} - -bool Task::HasToClean() { - return cleanup; -} - void Task::Stop() { stopped = true; } diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 546bbc6..4d782a0 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -22,14 +22,30 @@ int TaskMan::number = 0; bool TaskMan::inited = false; static int got_sigchild = 0; -static vector<pid_t> process; -static int nbprocess = 0; void taskman_sigchild(int sig) { - got_sigchild = 1; - process.push_back(wait(0)); + int status; + pid_t pid; + + pid = wait(&status); + if (TaskMan::GotChild(pid, status)) { + got_sigchild = 1; + } signal(SIGCHLD, taskman_sigchild); - nbprocess++; +} + +int TaskMan::GotChild(pid_t pid, int status) { + int r = 0; + + for (vector<w4pr_t>::iterator p = w4pr.begin(); p && (p != w4pr.end()); p++) { + if (p->pr == pid) { + p->flag = true; + p->status = status; + r = 1; + } + } + + return r; } void TaskMan::Init() throw (GeneralException) { @@ -141,11 +157,7 @@ void TaskMan::MainLoop() throw (GeneralException) { TaskList.erase(p); number--; p--; - if (t->HasToClean()) { - delete t; - } else { - Zombies.push_back(t); - } + Zombies.push_back(t); } } } @@ -172,7 +184,7 @@ void TaskMan::MainLoop() throw (GeneralException) { q->events = 0; } else { cerr << "==== TaskMan: adding watch over handle \"" << p->ha->GetName() << "\" for task \"" << p->T->GetName() << "\"\n"; - if (p->ha->CanWatch() { + if (p->ha->CanWatch()) { q->fd = p->ha->GetHandle(); q->events = (p->flags & W4_READING ? POLLIN : 0) | (p->flags & W4_WRITING ? POLLOUT : 0); } else { @@ -203,7 +215,11 @@ void TaskMan::MainLoop() throw (GeneralException) { r = select(highest + 1, &readfds, &writefds, &exceptfds, NULL); #endif if (r == -1) { - throw GeneralException(String("Error during poll: ") + strerror(errno)); + if (errno == EINTR) { + // child + } else { + throw GeneralException(String("Error during poll: ") + strerror(errno)); + } } else if (r == 0) { // timeout... } else { @@ -252,17 +268,10 @@ void TaskMan::MainLoop() throw (GeneralException) { if (q) { TaskList.erase(q); number--; - if (p->T->HasToClean()) { - delete p->T; - } else { - Zombies.push_back(p->T); - } + Zombies.push_back(p->T); w4ha.erase(p); p--; erased = true; - } else { - // Hu-ho, something wrong... - throw GeneralException("TaskMan: internal error (task not found)"); } } @@ -303,12 +312,8 @@ void TaskMan::MainLoop() throw (GeneralException) { } TaskList.erase(f); number--; - if (o->HasToClean()) { - delete o; - } else { - Zombies.push_back(o); - no_zombies = 0; - } + Zombies.push_back(o); + no_zombies = 0; } } else { delete t; |