From aa92df3c58daefb994da555fb45f2e3ee55f38d5 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 14 Nov 2001 16:59:02 +0000 Subject: Latest and various changes --- lib/Handle.cc | 2 +- lib/HttpServ.cc | 19 ++++++++++++++----- lib/Input.cc | 15 +++++++++++++++ lib/Output.cc | 30 ++++++++++++++++++++++++++++++ lib/String.cc | 4 ++-- lib/Task.cc | 12 +++++++++--- lib/TaskMan.cc | 8 +++----- 7 files changed, 74 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/Handle.cc b/lib/Handle.cc index 7ad7cc6..dd22b5c 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -96,7 +96,7 @@ void Handle::SetNonBlock(void) { } Handle & operator<<(Handle & h, const String & s) { - char * p; + const char * p; p = s.to_charp(); h.write(p, strlen(p)); diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 84078e0..3bec28f 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -7,9 +7,18 @@ String endhl = "\r\n", endnl = "\n"; -HttpServ::HttpServ(int port, const String & nname) : name(nname), localport(port) { - Listener.SetLocal("", port); - Listener.Listen(); +HttpServ::HttpServ(int port, const String & nname) throw (GeneralException) : name(nname), localport(port) { + bool r = true; + + r = Listener.SetLocal("", port); + if (r) { + r = Listener.Listen(); + } + + if (!r) { + throw GeneralException("Initialisation of the Mini HTTP-Server failed."); + } + cerr << "Mini HTTP-Server '" << name << "' ready and listening for port " << port << endl; } @@ -128,7 +137,7 @@ void HttpServ::ParseVars(Handle * s, int len) { s->read(&l, 1); t += l; } - cerr << "Post variables line: '" <> t; diff --git a/lib/Input.cc b/lib/Input.cc index 9ce7ca0..ad8991a 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -30,3 +30,18 @@ String Input::GetName() { return n; } +Stdin_t::Stdin_t() : Handle(dup(0)) { } + +bool Stdin_t::CanWrite() { + return 0; +} + +bool Stdin_t::CanRead() { + return 1; +} + +String Stdin_t::GetName() { + return "Stdin"; +} + +Stdin_t Stdin; diff --git a/lib/Output.cc b/lib/Output.cc index ab51c9f..9e7437f 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -30,3 +30,33 @@ String Output::GetName() { return n; } +Stdout_t::Stdout_t() : Handle(dup(1)) {} + +bool Stdout_t::CanWrite() { + return 1; +} + +bool Stdout_t::CanRead() { + return 0; +} + +String Stdout_t::GetName() { + return "Stdout"; +} + +Stderr_t::Stderr_t() : Handle(dup(2)) {} + +bool Stderr_t::CanWrite() { + return 1; +} + +bool Stderr_t::CanRead() { + return 0; +} + +String Stderr_t::GetName() { + return "Stderr"; +} + +Stdout_t Stdout; +Stderr_t Stderr; diff --git a/lib/String.cc b/lib/String.cc index 0e22de0..d64f065 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -47,7 +47,7 @@ String::~String() { free(str); } -char * String::set(char * s, ...) { +const char * String::set(char * s, ...) { va_list ap; va_start(ap, s); @@ -59,7 +59,7 @@ char * String::set(char * s, ...) { return t; } -char * String::to_charp(size_t from, ssize_t to) const { +const char * String::to_charp(size_t from, ssize_t to) const { if (to < 0) { strcpy(t, &(str[from])); } else { diff --git a/lib/Task.cc b/lib/Task.cc index 338eaba..fd1bf3f 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -1,9 +1,15 @@ +#include #include +#include "TaskMan.h" #include "Task.h" #include "String.h" -Task::Task() : state(TASK_ON_HOLD), suspended(false) {} -Task::~Task() {} +Task::Task() : state(TASK_ON_HOLD), suspended(false) { + TaskMan::AddTask(this); +} +Task::~Task() { + TaskMan::RemoveTask(this); +} int Task::Do() throw (GeneralException) { return TASK_ON_HOLD; @@ -55,6 +61,6 @@ void Task::WaitFor(pid_t p) { w4pr.push_back(p); } -void Task::WaitFor(struct timeval t) { +void Task::WaitFor(timeval t) { w4to.push_back(t); } diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 6a38491..479e25e 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -3,6 +3,8 @@ #include #include "TaskMan.h" +vector TaskMan::TaskList; +int TaskMan::number = 0; bool TaskMan::inited = false; static int got_sigchild = 0; @@ -16,10 +18,6 @@ void taskman_sigchild(int sig) { nbprocess++; } -TaskMan::TaskMan() throw (GeneralException) { - throw GeneralException("You can't instanciate a Task Manager."); -} - void TaskMan::Init() throw (GeneralException) { if (inited) { throw GeneralException("Task Manager already initialised."); @@ -69,7 +67,7 @@ void TaskMan::MainLoop() throw (GeneralException) { #endif try { - t->Do(); + t->Run(); } catch (TaskSwitch) { continue; -- cgit v1.2.3