aboutsummaryrefslogtreecommitdiffstats
path: root/remote-processor
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
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')
-rw-r--r--remote-processor/Android.mk12
-rw-r--r--remote-processor/CMakeLists.txt6
-rw-r--r--remote-processor/ListeningSocket.cpp19
-rw-r--r--remote-processor/ListeningSocket.h4
-rw-r--r--remote-processor/RemoteProcessorServer.cpp55
-rw-r--r--remote-processor/RemoteProcessorServer.h4
-rw-r--r--remote-processor/RemoteProcessorServerInterface.h5
-rw-r--r--remote-processor/Socket.cpp42
-rw-r--r--remote-processor/Socket.h1
9 files changed, 98 insertions, 50 deletions
diff --git a/remote-processor/Android.mk b/remote-processor/Android.mk
index b8050b1..784a917 100644
--- a/remote-processor/Android.mk
+++ b/remote-processor/Android.mk
@@ -49,9 +49,6 @@ common_cflags := \
-Werror \
-Wextra \
-Wno-unused-parameter \
- -pthread
-
-common_ldlibs := -pthread
#############################
# Target build
@@ -60,8 +57,9 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(common_src_files)
+LOCAL_STATIC_LIBRARIES := libpfw_utility
+
LOCAL_CFLAGS := $(common_cflags)
-LOCAL_LDLIBS := $(common_ldlibs)
LOCAL_MODULE := $(common_module)
LOCAL_MODULE_OWNER := intel
@@ -76,8 +74,10 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(common_src_files)
-LOCAL_CFLAGS := $(common_cflags)
-LOCAL_LDLIBS := $(common_ldlibs)
+LOCAL_STATIC_LIBRARIES := libpfw_utility_host
+
+LOCAL_CFLAGS := $(common_cflags) -pthread
+LOCAL_LDLIBS := -lpthread
LOCAL_MODULE := $(common_module)_host
LOCAL_MODULE_OWNER := intel
diff --git a/remote-processor/CMakeLists.txt b/remote-processor/CMakeLists.txt
index 598bd4f..27a41f9 100644
--- a/remote-processor/CMakeLists.txt
+++ b/remote-processor/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014, Intel Corporation
+# Copyright (c) 2014-2015, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
@@ -39,6 +39,8 @@ add_library(remote-processor SHARED
set(CMAKE_THREAD_PREFER_PTHREAD 1)
find_package(Threads REQUIRED)
-target_link_libraries(remote-processor ${CMAKE_THREAD_LIBS_INIT})
+include_directories("${PROJECT_SOURCE_DIR}/utility")
+
+target_link_libraries(remote-processor pfw_utility ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS remote-processor LIBRARY DESTINATION lib)
diff --git a/remote-processor/ListeningSocket.cpp b/remote-processor/ListeningSocket.cpp
index 1677d71..191d412 100644
--- a/remote-processor/ListeningSocket.cpp
+++ b/remote-processor/ListeningSocket.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,
@@ -39,6 +39,7 @@
#include <stdio.h>
#include <errno.h>
+#include <cstring>
#define base CSocket
@@ -52,7 +53,7 @@ CListeningSocket::CListeningSocket()
}
// Listen
-bool CListeningSocket::listen(uint16_t uiPort)
+bool CListeningSocket::listen(uint16_t uiPort, string &strError)
{
struct sockaddr_in server_addr;
@@ -62,19 +63,17 @@ bool CListeningSocket::listen(uint16_t uiPort)
// Bind
if (bind(getFd(), (struct sockaddr*)&server_addr, sizeof(struct sockaddr)) == -1) {
- std::ostringstream oss;
- oss << "CListeningSocket::listen::bind port " << uiPort;
- perror(oss.str().c_str());
-
+ std::ostringstream oss;
+ oss << uiPort;
+ strError = "Could not bind socket to port " + oss.str() + ": " + strerror(errno);
return false;
}
if (::listen(getFd(), 5) == -1) {
- std::ostringstream oss;
- oss << "CListeningSocket::listen::bind port " << uiPort;
- perror(oss.str().c_str());
-
+ std::ostringstream oss;
+ oss << uiPort;
+ strError = "Could not listen to port " + oss.str() + ": " + strerror(errno);
return false;
}
return true;
diff --git a/remote-processor/ListeningSocket.h b/remote-processor/ListeningSocket.h
index 8aa0608..3b5b614 100644
--- a/remote-processor/ListeningSocket.h
+++ b/remote-processor/ListeningSocket.h
@@ -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,
@@ -37,7 +37,7 @@ public:
CListeningSocket();
// Listen
- bool listen(uint16_t uiPort);
+ bool listen(uint16_t uiPort, std::string &strError);
// Accept
CSocket* accept();
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;
diff --git a/remote-processor/RemoteProcessorServer.h b/remote-processor/RemoteProcessorServer.h
index 202364b..08f93e4 100644
--- a/remote-processor/RemoteProcessorServer.h
+++ b/remote-processor/RemoteProcessorServer.h
@@ -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,
@@ -43,7 +43,7 @@ public:
virtual ~CRemoteProcessorServer();
// State
- virtual bool start();
+ virtual bool start(std::string &error);
virtual void stop();
virtual bool isStarted() const;
diff --git a/remote-processor/RemoteProcessorServerInterface.h b/remote-processor/RemoteProcessorServerInterface.h
index 19a799c..3ca3b76 100644
--- a/remote-processor/RemoteProcessorServerInterface.h
+++ b/remote-processor/RemoteProcessorServerInterface.h
@@ -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,
@@ -30,11 +30,12 @@
#pragma once
#include "RequestMessage.h"
+#include <string>
class IRemoteProcessorServerInterface
{
public:
- virtual bool start() = 0;
+ virtual bool start(std::string &strError) = 0;
virtual void stop() = 0;
virtual bool isStarted() const = 0;
diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp
index b36d32f..0aec7a2 100644
--- a/remote-processor/Socket.cpp
+++ b/remote-processor/Socket.cpp
@@ -39,8 +39,9 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/time.h>
+#include <signal.h>
-CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0))
+CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0)), mSendFlag(0)
{
assert(_iSockFd != -1);
@@ -50,6 +51,19 @@ CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0))
// they are ready to be sent, instead of waiting for more data on the
// socket.
setsockopt(_iSockFd, IPPROTO_TCP, TCP_NODELAY, (char *)&iNoDelay, sizeof(iNoDelay));
+
+ // Disable sigpipe reception on send
+# if not defined(SIGPIPE)
+ // Pipe signal does not exist, there no sigpipe to ignore on send
+# elif defined(SO_NOSIGPIPE)
+ const int set = 1;
+ setsockopt(_iSockFd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set));
+# elif defined(MSG_NOSIGNAL)
+ // Use flag NOSIGNAL on send call
+ mSendFlag = MSG_NOSIGNAL;
+# else
+# error Can not disable SIGPIPE
+# endif
}
CSocket::CSocket(int iSockId) : _iSockFd(iSockId)
@@ -59,7 +73,11 @@ CSocket::CSocket(int iSockId) : _iSockFd(iSockId)
CSocket::~CSocket()
{
- close(_iSockFd);
+ // fd might be invalide if send had an error.
+ // valgrind displays a warning if closing an invalid fd.
+ if (_iSockFd != -1) {
+ close(_iSockFd);
+ }
}
// Socket address init
@@ -108,7 +126,7 @@ bool CSocket::read(void* pvData, uint32_t uiSize)
while (uiSize) {
- int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+ int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, 0);
switch (iAccessedSize) {
case 0:
@@ -140,17 +158,19 @@ bool CSocket::write(const void* pvData, uint32_t uiSize)
while (uiSize) {
- int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+ int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, mSendFlag);
if (iAccessedSize == -1) {
- if (errno == ECONNRESET) {
- // Peer has disconnected
- _disconnected = true;
- }
- // errno == EINTR => The send system call was interrupted, try again
- if (errno != EINTR) {
- return false;
+ if (errno == EINTR) {
+ // The send system call was interrupted, try again
+ continue;
}
+
+ // An error occured, forget this socket
+ _disconnected = true;
+ close(_iSockFd);
+ _iSockFd = -1; // Avoid writing again on the same socket
+ return false;
} else {
uiSize -= iAccessedSize;
uiOffset += iAccessedSize;
diff --git a/remote-processor/Socket.h b/remote-processor/Socket.h
index 00bd8bc..8c3fb9f 100644
--- a/remote-processor/Socket.h
+++ b/remote-processor/Socket.h
@@ -108,4 +108,5 @@ private:
* See hasPeerDisconnected for more details.
*/
bool _disconnected;
+ int mSendFlag;
};