diff options
author | Pixel <Pixel> | 2001-11-27 20:16:05 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-27 20:16:05 +0000 |
commit | 5212a0752902e64bbd0e24b5c84edb0350e2d3f8 (patch) | |
tree | af1ea861fbb67d60a04e1fe4d740fd8edc9c8479 /lib | |
parent | 76b2e3c19278da49193aa1599a35197b279b4439 (diff) |
Last (?) bug of TaskMan.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/HttpServ.cc | 6 | ||||
-rw-r--r-- | lib/Task.cc | 10 | ||||
-rw-r--r-- | lib/TaskMan.cc | 57 |
3 files changed, 35 insertions, 38 deletions
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; |