diff options
Diffstat (limited to 'lib/server/ServerStream.h')
-rw-r--r-- | lib/server/ServerStream.h | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index a9b56169..3f6eed7e 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -17,6 +17,7 @@ #include <sys/wait.h> #endif +#include "autogen_ServerException.h" #include "Daemon.h" #include "SocketListen.h" #include "Utils.h" @@ -286,7 +287,7 @@ public: #endif // The derived class does some server magic with the connection - HandleConnection(*connection); + HandleConnection(connection); // Since rChildExit == true, the forked process will call _exit() on return from this fn return; @@ -305,7 +306,7 @@ public: #endif // !WIN32 // Just handle in this process SetProcessTitle("handling"); - HandleConnection(*connection); + HandleConnection(connection); SetProcessTitle("idle"); #ifndef WIN32 } @@ -344,10 +345,20 @@ public: p = ::waitpid(0 /* any child in process group */, &status, WNOHANG); - if(p == -1 && errno != ECHILD && errno != EINTR) + if(p == -1) { - THROW_EXCEPTION(ServerException, - ServerWaitOnChildError) + if (errno == ECHILD || errno == EINTR) + { + // Nothing actually happened, so there's no reason + // to wait again. + break; + } + else + { + THROW_SYS_ERROR("Failed to wait for daemon child " + "process", ServerException, + ServerWaitOnChildError); + } } else if(p == 0) { @@ -377,12 +388,12 @@ public: } #endif - virtual void HandleConnection(StreamType &rStream) + virtual void HandleConnection(std::auto_ptr<StreamType> apStream) { - Connection(rStream); + Connection(apStream); } - virtual void Connection(StreamType &rStream) = 0; + virtual void Connection(std::auto_ptr<StreamType> apStream) = 0; protected: // For checking code in derived classes -- use if you have an algorithm which |