summaryrefslogtreecommitdiffstats
path: root/remote-processor/RemoteProcessorServer.cpp
diff options
context:
space:
mode:
authorKevin Rocard <kevinx.rocard@intel.com>2014-04-25 15:11:12 +0200
committerMattijs Korpershoek <mattijsx.korpershoek@intel.com>2014-06-25 10:52:29 +0200
commite874c2575c1203648e71426cd34f747cbd34b2b4 (patch)
treee0d57fb36c4c77aeaca67f0f8b06d527fb82afbc /remote-processor/RemoteProcessorServer.cpp
parentef8d727ca0eb346af951d15d84ba6f2b9564adf5 (diff)
downloadexternal_parameter-framework-e874c2575c1203648e71426cd34f747cbd34b2b4.zip
external_parameter-framework-e874c2575c1203648e71426cd34f747cbd34b2b4.tar.gz
external_parameter-framework-e874c2575c1203648e71426cd34f747cbd34b2b4.tar.bz2
remote-proccessor detect partial message reception
BZ: 190038 Client disconnection during message reception is normal if no part of the message as been receive yet. Client disconnection in the middle of a packet reception is not normal but was not differentiated from the behaviour described above. Do not consider client disconnection on first read as an error. Consider it as an error on the followings. Change-Id: I34b50ba0af800f9e1fcdb51996b1b2f02a23cb3f Signed-off-by: Kevin Rocard <kevinx.rocard@intel.com> Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
Diffstat (limited to 'remote-processor/RemoteProcessorServer.cpp')
-rw-r--r--remote-processor/RemoteProcessorServer.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/remote-processor/RemoteProcessorServer.cpp b/remote-processor/RemoteProcessorServer.cpp
index 487379e..8c66109 100644
--- a/remote-processor/RemoteProcessorServer.cpp
+++ b/remote-processor/RemoteProcessorServer.cpp
@@ -30,6 +30,7 @@
#include "RemoteProcessorServer.h"
#include "ListeningSocket.h"
#include <iostream>
+#include <memory>
#include <assert.h>
#include <poll.h>
#include <unistd.h>
@@ -147,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) {
@@ -166,12 +167,18 @@ void CRemoteProcessorServer::handleNewConnection()
string strError;
///// Receive command
- if (!requestMessage.serialize(pClientSocket, false, strError)) {
-
- if (!pClientSocket->hasPeerDisconnected()) {
- cout << "Error while receiving message: " << strError << endl;
- }
- 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
@@ -195,13 +202,17 @@ void CRemoteProcessorServer::handleNewConnection()
CAnswerMessage answerMessage(strResult, bSuccess);
///// Send answer
- if (!answerMessage.serialize(pClientSocket, true, strError)) {
-
- // Bail out
- cout << "Error while sending message: " << strError << endl;
- 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;
}