From bcaa6e3580f5b227ab48693192c459cc72c30224 Mon Sep 17 00:00:00 2001 From: Sebastien Braun Date: Mon, 11 Oct 2010 12:27:27 +0200 Subject: Better error handling for PVSPrivInputHandler --- src/input/pvsPrivInputHandler.cpp | 21 ++++++++++++++++++--- src/input/pvsprivinputd.cpp | 4 +++- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src/input') diff --git a/src/input/pvsPrivInputHandler.cpp b/src/input/pvsPrivInputHandler.cpp index 84ccbae..d33697a 100644 --- a/src/input/pvsPrivInputHandler.cpp +++ b/src/input/pvsPrivInputHandler.cpp @@ -86,9 +86,24 @@ void PVSPrivInputHandler::canRead() if(!pvsPrivInputRecvMessage(_fd, _messageAssembly.data(), siz, pid, uid, gid, &err)) { - close(_fd); - deleteLater(); - return; + switch(err) + { + case EAGAIN: +#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN) + case EWOULDBLOCK: +#endif + // That's okay. Nothing to do. + break; + case 0: + // We'll survive. There was no actual error, just the library routine + // that decided it did not really want to receive that packet. + break; + default: + qWarning("Something bad just happened, and cannot handle it. Panicking."); + close(_fd); + deleteLater(); + return; + } } else { diff --git a/src/input/pvsprivinputd.cpp b/src/input/pvsprivinputd.cpp index e6ae155..df3acfc 100644 --- a/src/input/pvsprivinputd.cpp +++ b/src/input/pvsprivinputd.cpp @@ -182,7 +182,9 @@ int main(int argc, char** argv) } // Install our main object - PVSPrivInputHandler handler(sock); + PVSPrivInputHandler* handler = new PVSPrivInputHandler(sock, &app); + // When the handler gets deleted, we want to quit the application + QObject::connect(handler, SIGNAL(destroyed(QObject*)), &app, SLOT(quit())); // set up signal handling: if(socketpair(AF_UNIX, SOCK_DGRAM, 0, signalFds) < 0) -- cgit v1.2.3-55-g7522