summaryrefslogtreecommitdiff
path: root/server/miav_server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/miav_server.cc')
-rw-r--r--server/miav_server.cc65
1 files changed, 39 insertions, 26 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;
}