summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-14 16:59:02 +0000
committerPixel <Pixel>2001-11-14 16:59:02 +0000
commitaa92df3c58daefb994da555fb45f2e3ee55f38d5 (patch)
tree6105f0ced059af0fceb10a29f318d0c13c83d051 /lib
parent9235fbc2a736da2c68eb2dc0a3c1007b4a202d5e (diff)
Latest and various changes
Diffstat (limited to 'lib')
-rw-r--r--lib/Handle.cc2
-rw-r--r--lib/HttpServ.cc19
-rw-r--r--lib/Input.cc15
-rw-r--r--lib/Output.cc30
-rw-r--r--lib/String.cc4
-rw-r--r--lib/Task.cc12
-rw-r--r--lib/TaskMan.cc8
7 files changed, 74 insertions, 16 deletions
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 << "'\n";
+ cerr << "Post variables line: '" << t << "'\n";
// Les variables sont sous la forme 'var1=val1&var2=val2&val3=var3'. Donc le nombre d'occurences
@@ -180,7 +189,7 @@ void HttpServ::ParseVars(Handle * s, int len) {
bool HttpServ::ParseUri(String & file, String & domain, Handle * s) {
String t, Uri;
bool post = false;
- char * p = NULL;
+ const char * p = NULL;
ssize_t sppos;
*s >> 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 <sys/time.h>
#include <iostream.h>
+#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 <vector.h>
#include "TaskMan.h"
+vector<Task *> 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;