From 52fd913be8b044f1d064973c53b4467e5bd153fe Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 19 Jun 2005 11:44:14 +0000 Subject: Cleaned up a log of logging. Fixed server queue (shouldn't happen). Added user and group lookup. --- src/miav_daemon.cc | 59 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'src/miav_daemon.cc') diff --git a/src/miav_daemon.cc b/src/miav_daemon.cc index 520a2fb..b164e92 100644 --- a/src/miav_daemon.cc +++ b/src/miav_daemon.cc @@ -31,6 +31,11 @@ /* * $Log$ + * Revision 1.5 2005/06/19 11:44:14 deva + * Cleaned up a log of logging. + * Fixed server queue (shouldn't happen). + * Added user and group lookup. + * * Revision 1.4 2005/06/16 21:28:57 deva * Rewrote thread object * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to @@ -78,26 +83,50 @@ int MiavDaemon::daemon_main() info.info("Listening on port %d", port); Socket *socket = new Socket(port, &info); + if(socket->hasError()) { + info.error("Listening socket has errors, quitting."); + delete socket; + return 1; + } + while(1) { Socket *csocket = new Socket(socket->slisten()); - if(csocket->isConnected()) { - childpid = fork(); + + if(socket->hasError()) { + info.error("Server socket has errors, quitting."); + delete csocket; + break; + } + + if(csocket->hasError()) { + info.error("Child socket has errors, quitting."); + delete csocket; + break; + } + + if(!csocket->isConnected()) { + info.error("Child socket is not connected, quitting."); + delete csocket; + break; + } + + childpid = fork(); + + switch(childpid) { + case -1: // fork() returns -1 on failure + info.log("Fork error: %s", strerror(errno)); + exit(1); + case 0: // fork() returns 0 to the child process + delete socket; // Close listen socket. + newConnection(csocket, &info); + delete csocket; // Close communication socket. + exit(0); - switch(childpid) { - case -1: // fork() returns -1 on failure - info.log("Fork error: %s", strerror(errno)); - exit(1); - case 0: // fork() returns 0 to the child process - delete socket; // Close listen socket. - newConnection(csocket, &info); - delete csocket; // Close communication socket. - exit(0); - - default: // fork() returns new pid to the parent process - break; - } + default: // fork() returns new pid to the parent process + break; } } + delete socket; return 0; } -- cgit v1.2.3