summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordeva <deva>2006-08-25 21:20:07 +0000
committerdeva <deva>2006-08-25 21:20:07 +0000
commit8196872e3b240ef93fc17dd3c05a7d97a8015d88 (patch)
treee531edeb1c7178a8e58170c84645ce8eb706624e /server
parent347b1d8ed3a4f780f3a5c0d57a04eab05ca517a2 (diff)
Rearranged the network and socket code.origin
Added status messages sent over the network using udp packets.
Diffstat (limited to 'server')
-rw-r--r--server/miav_server.cc65
-rw-r--r--server/server.cc2
-rw-r--r--server/server_status.cc59
-rw-r--r--server/server_status.h25
4 files changed, 61 insertions, 90 deletions
diff --git a/server/miav_server.cc b/server/miav_server.cc
index 8cd7a42..1682dad 100644
--- a/server/miav_server.cc
+++ b/server/miav_server.cc
@@ -31,14 +31,15 @@
#include "info_console.h"
+#include "server_status.h"
+
#include <stdio.h>
#include <string.h>
#include <string>
#include "server.h"
-#include "socket.h"
-#include "network.h"
+#include "tcp_socket.h"
#include <signal.h>
#include <errno.h>
@@ -177,59 +178,71 @@ int main(int argc, char *argv[])
if(config.get("server_port", &port))
info.error("Could not read symbol [server_port] from the conf file!");
- pid_t childpid; // variable to store the child's pid
-
signal(SIGCLD, SIG_IGN); // Ved SIGCHILD til IGNORE maa wait/waitpid ikke kaldes
// (ellers kommer der kernel-brok)
+ pid_t childpid;
+ childpid = fork();
+ switch(childpid) {
+ case -1:
+ MIaV::info->log("Fork error: %s", strerror(errno));
+ return 1;
+
+ case 0: // fork() returns 0 to the child process
+ if(server_status(port)) exit(1);
+ return 0;
+
+ default: // fork() returns new pid to the parent process
+ break;
+ }
+
MIaV::info->info("Starting MIaV server v. %s", VERSION);
MIaV::info->info("Listening on port %d", port);
- Socket *socket = new Socket(port);
-
- if(socket->hasError()) {
+ TCPSocket socket(port);
+ /*
+ if(socket.hasError()) {
MIaV::info->error("Listening socket has errors, quitting.");
- delete socket;
return 1;
}
-
+ */
while(1) {
- Socket *csocket = new Socket(socket->slisten());
+ TCPSocket csocket;
+ if(socket.listen(&csocket)) {
+ MIaV::info->error("Server socket has errors, quitting. %s", socket.error().c_str());
+ }
- if(socket->hasError()) {
+ /*
+ if(socket.hasError()) {
MIaV::info->error("Server socket has errors, quitting.");
- delete csocket;
break;
}
-
- if(csocket->hasError()) {
+ */
+ /*
+ if(csocket.hasError()) {
MIaV::info->error("Child socket has errors, quitting.");
- delete csocket;
break;
}
-
- if(!csocket->isConnected()) {
+ */
+ /*
+ if(!csocket.isConnected()) {
MIaV::info->error("Child socket is not connected, quitting.");
- delete csocket;
break;
}
-
+ */
childpid = fork();
-
switch(childpid) {
case -1: // fork() returns -1 on failure
MIaV::info->log("Fork error: %s", strerror(errno));
- exit(1);
+ return 1;
+
case 0: // fork() returns 0 to the child process
- delete socket; // Close listen socket.
- newConnection(csocket);
- delete csocket; // Close communication socket.
- exit(0);
+ newConnection(&csocket);
+ return 0;
default: // fork() returns new pid to the parent process
break;
}
}
- delete socket;
return 0;
}
diff --git a/server/server.cc b/server/server.cc
index 5088fa5..dfe024a 100644
--- a/server/server.cc
+++ b/server/server.cc
@@ -65,7 +65,7 @@ void newConnection(Socket *socket)
Network network(socket);
MIaV::info->info("CONNECTION OPENED");
- MIaV::info->info("New connection (%s)", inet_ntoa(socket->socketaddr.sin_addr));
+ MIaV::info->info("New connection (%s)", socket->address().c_str());
Frame *frame;
while((frame = network.recvFrame())) {
diff --git a/server/server_status.cc b/server/server_status.cc
index 88bd35c..b1837b8 100644
--- a/server/server_status.cc
+++ b/server/server_status.cc
@@ -3,7 +3,7 @@
* server_status.cc
*
* Fri Apr 29 13:58:26 CEST 2005
- * Copyright 2005 Bent Bisballe
+ * Copyright 2005 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,52 +24,31 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
#include "server_status.h"
-#include "info.h"
-#include <stdio.h>
-ServerStatus::ServerStatus()
-{
- gettimeofday(&oldtime, NULL);
-
- for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
- frametime[cnt] = 41660;
- }
-
- gettimeofday(&time, NULL);
+#include "udp_socket.h"
+#include "status.h"
- interval = 0;
-}
-
-ServerStatus::~ServerStatus()
+int server_status(int port)
{
-}
+ status_t s;
+ status_request_t r;
-void ServerStatus::checkPoint()
-{
- for(int cnt = BUFFERSIZE - 1; cnt > 0; cnt--) {
- frametime[cnt] = frametime[cnt-1];
- }
- frametime[0] = (1000000 * time.tv_sec + time.tv_usec) - (1000000 * oldtime.tv_sec + oldtime.tv_usec);
+ s.diskspace_max = 0xff;
+ s.diskspace = 0;
+
+ s.load_max = 0xff;
+ s.load = 0;
- oldtime.tv_sec = time.tv_sec;
- oldtime.tv_usec = time.tv_usec;
+ while(1) {
+ UDPSocket socket(port);
- gettimeofday(&time, NULL);
+ if(socket.read(&r, sizeof(r)) == -1) fprintf(stderr, "ERROR! READ %s\n", socket.error().c_str());
+ if(socket.write(&s, sizeof(s)) == -1) fprintf(stderr, "ERROR! WRITE %s\n", socket.error().c_str());
- interval += frametime[0];
- if(interval > UPD) {
- interval = 0;
- double total = 0.0;
- for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
- total += (double)frametime[cnt];
- }
- MIaV::info->info("Status - fps: %f", 1000000.0 / (total / (double)BUFFERSIZE));
+ s.diskspace++;
+ s.load++;
}
-
-}
-/*
-date(1), gettimeofday(2), ctime(3), ftime(3)
-*/
+ return 0;
+}
diff --git a/server/server_status.h b/server/server_status.h
index 82ec8ec..25346ec 100644
--- a/server/server_status.h
+++ b/server/server_status.h
@@ -3,7 +3,7 @@
* server_status.h
*
* Fri Apr 29 13:58:26 CEST 2005
- * Copyright 2005 Bent Bisballe
+ * Copyright 2005 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,30 +24,9 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "config.h"
#ifndef __MIAV_SERVER_STATUS_H__
#define __MIAV_SERVER_STATUS_H__
-#include <sys/time.h>
-
-// How many steps to do avarage calculation over.
-#define BUFFERSIZE 100
-
-// Interval in us (microseconds)
-#define UPD 60 * 1000 * 1000 // 1 minute
-
-class ServerStatus {
-public:
- ServerStatus();
- ~ServerStatus();
-
- void checkPoint();
-
-private:
- long long interval;
- unsigned int frametime[BUFFERSIZE];
- struct timeval time;
- struct timeval oldtime;
-};
+int server_status(int port);
#endif/*__MIAV_SERVER_STATUS_H__*/