summaryrefslogtreecommitdiffstats
path: root/remote-processor/RemoteProcessorServer.cpp
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2015-07-15 15:37:57 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2015-07-15 17:09:51 -0700
commita9be2d378b7ad84e679a48efa81f42fb54f85d9a (patch)
tree587d34728dac3517a213d6d2a9a6ebdecd4e7531 /remote-processor/RemoteProcessorServer.cpp
parentc99720d29f2ee618cc74c9336d2cd2a26544c020 (diff)
downloadexternal_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.zip
external_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.tar.gz
external_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.tar.bz2
Drop release v2.6.0+no-stlport
Bug 246391 Change-Id: I662b7b0f90c97cb169978e1b64ad1fe32c440cf5 Signed-off-by: Jean-Michel Trivi <jmtrivi@google.com>
Diffstat (limited to 'remote-processor/RemoteProcessorServer.cpp')
-rw-r--r--remote-processor/RemoteProcessorServer.cpp55
1 files changed, 40 insertions, 15 deletions
diff --git a/remote-processor/RemoteProcessorServer.cpp b/remote-processor/RemoteProcessorServer.cpp
index c1d87e5..e289d4e 100644
--- a/remote-processor/RemoteProcessorServer.cpp
+++ b/remote-processor/RemoteProcessorServer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2014, Intel Corporation
+ * Copyright (c) 2011-2015, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@@ -29,12 +29,14 @@
*/
#include "RemoteProcessorServer.h"
#include "ListeningSocket.h"
+#include "FullIo.hpp"
#include <iostream>
#include <memory>
#include <assert.h>
#include <poll.h>
#include <unistd.h>
-#include <strings.h>
+#include <string.h>
+#include <errno.h>
#include "RequestMessage.h"
#include "AnswerMessage.h"
#include "RemoteCommandHandler.h"
@@ -44,8 +46,6 @@ using std::string;
CRemoteProcessorServer::CRemoteProcessorServer(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler) :
_uiPort(uiPort), _pCommandHandler(pCommandHandler), _bIsStarted(false), _pListeningSocket(NULL), _ulThreadId(0)
{
- // Create inband pipe
- pipe(_aiInbandPipe);
}
CRemoteProcessorServer::~CRemoteProcessorServer()
@@ -54,27 +54,38 @@ CRemoteProcessorServer::~CRemoteProcessorServer()
}
// State
-bool CRemoteProcessorServer::start()
+bool CRemoteProcessorServer::start(string &error)
{
assert(!_bIsStarted);
- // Create server socket
- _pListeningSocket = new CListeningSocket;
+ if (pipe(_aiInbandPipe) == -1) {
+ error = "Could not create a pipe for remote processor communication: ";
+ error += strerror(errno);
+ return false;
+ }
- if (!_pListeningSocket->listen(_uiPort)) {
+ // Create server socket
+ std::auto_ptr<CListeningSocket> pListeningSocket(new CListeningSocket);
- // Remove listening socket
- delete _pListeningSocket;
- _pListeningSocket = NULL;
+ if (!pListeningSocket->listen(_uiPort, error)) {
return false;
}
+ // Thread needs to access to the listning socket.
+ _pListeningSocket = pListeningSocket.get();
// Create thread
- pthread_create(&_ulThreadId, NULL, thread_func, this);
+ errno = pthread_create(&_ulThreadId, NULL, thread_func, this);
+ if (errno != 0) {
+
+ error = "Could not create a remote processor thread: ";
+ error += strerror(errno);
+ return false;
+ }
// State
_bIsStarted = true;
+ pListeningSocket.release();
return true;
}
@@ -89,10 +100,20 @@ void CRemoteProcessorServer::stop()
// Cause exiting of the thread
uint8_t ucData = 0;
- write(_aiInbandPipe[1], &ucData, sizeof(ucData));
+ if (not utility::fullWrite(_aiInbandPipe[1], &ucData, sizeof(ucData))) {
+ std::cerr << "Could not query command processor thread to terminate: "
+ "fail to write on inband pipe: "
+ << strerror(errno) << std::endl;
+ assert(false);
+ }
// Join thread
- pthread_join(_ulThreadId, NULL);
+ errno = pthread_join(_ulThreadId, NULL);
+ if (errno != 0) {
+ std::cout << "Could not join with remote processor thread: "
+ << strerror(errno) << std::endl;
+ assert(false);
+ }
_bIsStarted = false;
@@ -139,7 +160,11 @@ void CRemoteProcessorServer::run()
// Consume exit request
uint8_t ucData;
- read(_aiInbandPipe[0], &ucData, sizeof(ucData));
+ if (not utility::fullRead(_aiInbandPipe[0], &ucData, sizeof(ucData))) {
+ std::cerr << "Remote processor could not receive exit request"
+ << strerror(errno) << std::endl;
+ assert(false);
+ }
// Exit
return;