summaryrefslogtreecommitdiff
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
parent9235fbc2a736da2c68eb2dc0a3c1007b4a202d5e (diff)
Latest and various changes
-rw-r--r--include/HttpServ.h2
-rw-r--r--include/Input.h11
-rw-r--r--include/Makefile.am4
-rw-r--r--include/Output.h21
-rw-r--r--include/String.h4
-rw-r--r--include/Task.h3
-rw-r--r--include/TaskMan.h13
-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
14 files changed, 119 insertions, 29 deletions
diff --git a/include/HttpServ.h b/include/HttpServ.h
index 5074639..7ac40e2 100644
--- a/include/HttpServ.h
+++ b/include/HttpServ.h
@@ -18,7 +18,7 @@
class HttpServ : public Base {
public:
- HttpServ(int = 1500, const String & = String("GruiK Server v0.1"));
+ HttpServ(int = 1500, const String & = String("GruiK Server v0.1")) throw (GeneralException);
~HttpServ() {}
void MainLoop(Action *);
private:
diff --git a/include/Input.h b/include/Input.h
index f9a3df5..682cee1 100644
--- a/include/Input.h
+++ b/include/Input.h
@@ -20,6 +20,17 @@ class Input : public Handle {
String n;
};
+class Stdin_t : public Handle {
+ public:
+ Stdin_t();
+ virtual ~Stdin_t() {}
+ virtual bool CanWrite();
+ virtual bool CanRead();
+ virtual String GetName();
+};
+
+extern Stdin_t Stdin;
+
#else
#error This only works with a C++ compiler
#endif
diff --git a/include/Makefile.am b/include/Makefile.am
index ac1f63c..bc93b8d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,5 +1,5 @@
-includedir = $(prefix)/include/@PACKAGE@
-include_HEADERS = \
+#includedir = $(prefix)/include/@PACKAGE@
+pkginclude_HEADERS = \
Exceptions.h Handle.h String.h Output.h Socket.h HttpServ.h Variables.h Menu.h \
Action.h Message.h Form.h Confirm.h Table.h IRC.h Task.h Buffer.h General.h \
CopyJob.h ReadJob.h Regex.h TaskMan.h
diff --git a/include/Output.h b/include/Output.h
index ef76012..4e1e092 100644
--- a/include/Output.h
+++ b/include/Output.h
@@ -20,6 +20,27 @@ class Output : public Handle {
String n;
};
+class Stdout_t : public Handle {
+ public:
+ Stdout_t();
+ virtual ~Stdout_t() {}
+ virtual bool CanWrite();
+ virtual bool CanRead();
+ virtual String GetName();
+};
+
+class Stderr_t : public Handle {
+ public:
+ Stderr_t();
+ virtual ~Stderr_t() {}
+ virtual bool CanWrite();
+ virtual bool CanRead();
+ virtual String GetName();
+};
+
+extern Stdout_t Stdout;
+extern Stderr_t Stderr;
+
#else
#error This only works with a C++ compiler
#endif
diff --git a/include/String.h b/include/String.h
index c6afdb2..ddb0cde 100644
--- a/include/String.h
+++ b/include/String.h
@@ -47,8 +47,8 @@ class String : public Base {
String(int);
String(double);
~String();
- char * set(char *, ...);
- char * to_charp(size_t = 0, ssize_t = -1) const;
+ const char * set(char *, ...);
+ const char * to_charp(size_t = 0, ssize_t = -1) const;
String extract(size_t = 0, ssize_t = -1) const;
char * strdup(size_t = 0, ssize_t = -1) const;
int to_int() const;
diff --git a/include/Task.h b/include/Task.h
index 675b2ed..f2d4b0b 100644
--- a/include/Task.h
+++ b/include/Task.h
@@ -3,6 +3,7 @@
#ifdef __cplusplus
#include <unistd.h>
+#include <sys/time.h>
#include <vector.h>
#include <Exceptions.h>
#include <Handle.h>
@@ -31,7 +32,7 @@ class Task : public Base {
vector<Handle *> w4ha;
vector<Task *> w4ta;
vector<pid_t> w4pr;
- vector<struct timeval> w4to;
+ vector<timeval> w4to;
};
#else
diff --git a/include/TaskMan.h b/include/TaskMan.h
index dc8c913..16bc0ee 100644
--- a/include/TaskMan.h
+++ b/include/TaskMan.h
@@ -7,14 +7,13 @@
class TaskMan : public Base {
public:
- TaskMan() throw (GeneralException);
- int AddTask(Task *);
- int TaskMan::RemoveTask(Task *);
- void Init() throw (GeneralException);
- void MainLoop() throw (GeneralException);
+ static int AddTask(Task *);
+ static int RemoveTask(Task *);
+ static void Init() throw (GeneralException);
+ static void MainLoop() throw (GeneralException);
private:
- vector<Task *> TaskList;
- int number;
+ static vector<Task *> TaskList;
+ static int number;
static bool inited;
};
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;