summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Handle.h2
-rw-r--r--include/HttpServ.h2
-rw-r--r--include/Socket.h1
-rw-r--r--lib/Handle.cc9
-rw-r--r--lib/Socket.cc14
-rw-r--r--lib/TaskMan.cc8
6 files changed, 29 insertions, 7 deletions
diff --git a/include/Handle.h b/include/Handle.h
index 21d6780..45a9432 100644
--- a/include/Handle.h
+++ b/include/Handle.h
@@ -44,7 +44,7 @@ class Handle : public Base {
void close();
int GetHandle();
virtual bool CanWatch();
-
+ virtual void Dup(const Handle &);
protected:
Handle(int h);
private:
diff --git a/include/HttpServ.h b/include/HttpServ.h
index 2518c55..5860dd7 100644
--- a/include/HttpServ.h
+++ b/include/HttpServ.h
@@ -20,7 +20,7 @@
class HttpServ : public Task {
public:
HttpServ(Action *, int = 1500, const String & = String("GruiK Server v0.1")) throw (GeneralException);
- ~HttpServ();
+ virtual ~HttpServ();
void SetMenu(Action *);
virtual String GetName();
diff --git a/include/Socket.h b/include/Socket.h
index 9e0f85f..c6402cb 100644
--- a/include/Socket.h
+++ b/include/Socket.h
@@ -42,6 +42,7 @@ class Socket : public Handle {
virtual bool CanRead();
virtual bool CanWrite();
virtual String GetName();
+ int GetPort();
private:
Socket(int s);
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 253ddbf..c02bc55 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -160,4 +160,11 @@ time_t Handle::GetModif(void) {
bool Handle::CanWatch(void) {
return true;
-} \ No newline at end of file
+}
+
+void Handle::Dup(const Handle & H) {
+ close();
+ if (H.h >= 0) {
+ h = dup(H.h);
+ }
+}
diff --git a/lib/Socket.cc b/lib/Socket.cc
index d3d7c19..f35bb72 100644
--- a/lib/Socket.cc
+++ b/lib/Socket.cc
@@ -122,3 +122,17 @@ Socket Socket::Accept(void) throw (GeneralException) {
return Socket(h);
}
}
+
+int Socket::GetPort() {
+ int r;
+ struct sockaddr_in localsocketaddr;
+ socklen_t locallen = sizeof(localsocketaddr);
+
+ if (getsockname(GetHandle(), (struct sockaddr *) &localsocketaddr, &locallen)) {
+ return -1;
+ }
+
+ r = ntohs(localsocketaddr.sin_port);
+
+ return r;
+}
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc
index f18bcf7..5709d02 100644
--- a/lib/TaskMan.cc
+++ b/lib/TaskMan.cc
@@ -147,7 +147,7 @@ void TaskMan::MainLoop() throw (GeneralException) {
if (stopped) return;
-// cerr << "-=- TaskMan: begin main loop with " << number << " task to manage.\n";
+ cerr << "-=- TaskMan: begin main loop with " << number << " task to manage.\n";
no_burst = 0;
while (!no_burst) {
@@ -157,7 +157,7 @@ void TaskMan::MainLoop() throw (GeneralException) {
Task * t = *p;
if (t->GetState() == TASK_BURST) {
-// cerr << "-=- TaskMan: running burning task " << t->GetName() << endl;
+ cerr << "-=- TaskMan: running burning task " << t->GetName() << endl;
t->Run();
/* if the task added some new tasks, we have to rerun the loop */
no_burst = 0;
@@ -274,7 +274,7 @@ void TaskMan::MainLoop() throw (GeneralException) {
touched = false;
if ((p->ha->GetHandle() == fd) && (!p->T->IsStopped()) && (p->T->GetState() != TASK_DONE) && (!p->dirthy)) {
// We've got one, launch it.
-// cerr << "-=- TaskMan: launching task " << p->T->GetName() << " for handle " << p->ha->GetHandle() << endl;
+ cerr << "-=- TaskMan: launching task " << p->T->GetName() << " for handle " << p->ha->GetHandle() << endl;
w4ha_t w4 = *p;
p->dirthy = true;
@@ -320,7 +320,7 @@ void TaskMan::MainLoop() throw (GeneralException) {
}
if ((o = t->WaitedBy())) {
-// cerr << "-=- TaskMan: running task " << o->GetName() << " for task " << t->GetName() << endl;
+ cerr << "-=- TaskMan: running task " << o->GetName() << " for task " << t->GetName() << endl;
o->Run();
if (o->GetState() == TASK_DONE) {