From 8196872e3b240ef93fc17dd3c05a7d97a8015d88 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 25 Aug 2006 21:20:07 +0000 Subject: Rearranged the network and socket code. Added status messages sent over the network using udp packets. --- server/miav_server.cc | 65 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'server/miav_server.cc') 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 #include #include #include "server.h" -#include "socket.h" -#include "network.h" +#include "tcp_socket.h" #include #include @@ -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; } -- cgit v1.2.3