summaryrefslogtreecommitdiffstats
path: root/remote-processor/RemoteProcessorServer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'remote-processor/RemoteProcessorServer.cpp')
-rw-r--r--remote-processor/RemoteProcessorServer.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/remote-processor/RemoteProcessorServer.cpp b/remote-processor/RemoteProcessorServer.cpp
index daa4894..8c66109 100644
--- a/remote-processor/RemoteProcessorServer.cpp
+++ b/remote-processor/RemoteProcessorServer.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (c) 2011-2014, Intel Corporation
* All rights reserved.
*
@@ -29,6 +29,8 @@
*/
#include "RemoteProcessorServer.h"
#include "ListeningSocket.h"
+#include <iostream>
+#include <memory>
#include <assert.h>
#include <poll.h>
#include <unistd.h>
@@ -146,15 +148,15 @@ void CRemoteProcessorServer::run()
// New connection
void CRemoteProcessorServer::handleNewConnection()
{
- CSocket* pClientSocket = _pListeningSocket->accept();
+ const auto_ptr<CSocket> clientSocket(_pListeningSocket->accept());
- if (!pClientSocket) {
+ if (clientSocket.get() == NULL) {
return;
}
// Set timeout
- pClientSocket->setTimeout(5000);
+ clientSocket->setTimeout(5000);
// Process all incoming requests from the client
while (true) {
@@ -163,11 +165,20 @@ void CRemoteProcessorServer::handleNewConnection()
// Create command message
CRequestMessage requestMessage;
+ string strError;
///// Receive command
- if (!requestMessage.serialize(pClientSocket, false)) {
-
- // Bail out
- break;
+ CRequestMessage::Result res;
+ res = requestMessage.serialize(clientSocket.get(), false, strError);
+
+ switch (res) {
+ case CRequestMessage::error:
+ cout << "Error while receiving message: " << strError << endl;
+ // fall through
+ case CRequestMessage::peerDisconnected:
+ // Consider peer disconnection as normal, no log
+ return; // Bail out
+ case CRequestMessage::success:
+ break; // No error, continue
}
// Actually process the request
@@ -191,12 +202,17 @@ void CRemoteProcessorServer::handleNewConnection()
CAnswerMessage answerMessage(strResult, bSuccess);
///// Send answer
- if (!answerMessage.serialize(pClientSocket, true)) {
-
- // Bail out
- break;
+ res = answerMessage.serialize(clientSocket.get(), true, strError);
+
+ switch (res) {
+ case CRequestMessage::peerDisconnected:
+ // Peer should not disconnect while waiting for an answer
+ // Fall through to log the error and bail out
+ case CRequestMessage::error:
+ cout << "Error while receiving message: " << strError << endl;
+ return; // Bail out
+ case CRequestMessage::success:
+ break; // No error, continue
}
}
- // Remove client socket
- delete pClientSocket;
}