diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-04-27 23:18:16 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-04-27 23:18:16 +0000 |
commit | ec6ac60f2191e820b3cf6601a07840aefef6b33a (patch) | |
tree | 0596c0ffd5fbbf4724af1002b32684fbe6f8a770 | |
parent | a50b7944e10872c9a226d6e1286f8f5fb65b18a2 (diff) | |
parent | bc5c94366c071965c025fac450162d7ff6a29563 (diff) | |
download | parameter-framework-ec6ac60f2191e820b3cf6601a07840aefef6b33a.tar.gz |
Snap for 5511022 from bc5c94366c071965c025fac450162d7ff6a29563 to qt-release
Change-Id: Ib127d621670690ef7609094b91436a394347954d
35 files changed, 1380 insertions, 104 deletions
@@ -2,4 +2,5 @@ # Please update this list if you find better candidates. jeffbailey@google.com rtenneti@google.com -francois.gaffie@intel.com # most recent significant change? +krocard@google.com +elaurent@google.com diff --git a/asio-1.10.6/include/asio/detail/config.hpp b/asio-1.10.6/include/asio/detail/config.hpp index 15797ee..89f3a47 100644 --- a/asio-1.10.6/include/asio/detail/config.hpp +++ b/asio-1.10.6/include/asio/detail/config.hpp @@ -50,7 +50,7 @@ // If ASIO_MOVE_CAST isn't defined, and move support is available, define // ASIO_MOVE_ARG and ASIO_MOVE_CAST to take advantage of rvalue // references and perfect forwarding. -#if defined(ASIO_HAS_MOVE) && !defined(ASIO_MOVE_CAST) +#if !defined(ASIO_MOVE_CAST) # define ASIO_MOVE_ARG(type) type&& # define ASIO_MOVE_CAST(type) static_cast<type&&> # define ASIO_MOVE_CAST2(type1, type2) static_cast<type1, type2&&> diff --git a/asio-1.10.6/include/asio/generic/basic_endpoint.hpp b/asio-1.10.6/include/asio/generic/basic_endpoint.hpp new file mode 100644 index 0000000..cf9ffdb --- /dev/null +++ b/asio-1.10.6/include/asio/generic/basic_endpoint.hpp @@ -0,0 +1,182 @@ +// +// generic/basic_endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_GENERIC_BASIC_ENDPOINT_HPP +#define ASIO_GENERIC_BASIC_ENDPOINT_HPP + + +#include "asio/detail/config.hpp" +#include "asio/generic/detail/endpoint.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace generic { + +/// Describes an endpoint for any socket type. +/** + * The asio::generic::basic_endpoint class template describes an endpoint + * that may be associated with any socket type. + * + * @note The socket types sockaddr type must be able to fit into a + * @c sockaddr_storage structure. + * + * @par Thread Safety + * @e Distinct @e objects: Safe.@n + * @e Shared @e objects: Unsafe. + * + * @par Concepts: + * Endpoint. + */ +template <typename Protocol> +class basic_endpoint +{ +public: + /// The protocol type associated with the endpoint. + typedef Protocol protocol_type; + + /// The type of the endpoint structure. This type is dependent on the + /// underlying implementation of the socket layer. + typedef asio::detail::socket_addr_type data_type; + + /// Default constructor. + basic_endpoint() + { + } + + /// Construct an endpoint from the specified socket address. + basic_endpoint(const void* socket_address, + std::size_t socket_address_size, int socket_protocol = 0) + : impl_(socket_address, socket_address_size, socket_protocol) + { + } + + /// Construct an endpoint from the specific endpoint type. + template <typename Endpoint> + basic_endpoint(const Endpoint& endpoint) + : impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol()) + { + } + + /// Copy constructor. + basic_endpoint(const basic_endpoint& other) + : impl_(other.impl_) + { + } + + /// Move constructor. + basic_endpoint(basic_endpoint&& other) + : impl_(other.impl_) + { + } + + /// Assign from another endpoint. + basic_endpoint& operator=(const basic_endpoint& other) + { + impl_ = other.impl_; + return *this; + } + + /// Move-assign from another endpoint. + basic_endpoint& operator=(basic_endpoint&& other) + { + impl_ = other.impl_; + return *this; + } + + /// The protocol associated with the endpoint. + protocol_type protocol() const + { + return protocol_type(impl_.family(), impl_.protocol()); + } + + /// Get the underlying endpoint in the native type. + data_type* data() + { + return impl_.data(); + } + + /// Get the underlying endpoint in the native type. + const data_type* data() const + { + return impl_.data(); + } + + /// Get the underlying size of the endpoint in the native type. + std::size_t size() const + { + return impl_.size(); + } + + /// Set the underlying size of the endpoint in the native type. + void resize(std::size_t new_size) + { + impl_.resize(new_size); + } + + /// Get the capacity of the endpoint in the native type. + std::size_t capacity() const + { + return impl_.capacity(); + } + + /// Compare two endpoints for equality. + friend bool operator==(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e1.impl_ == e2.impl_; + } + + /// Compare two endpoints for inequality. + friend bool operator!=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e1.impl_ == e2.impl_); + } + + /// Compare endpoints for ordering. + friend bool operator<(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e1.impl_ < e2.impl_; + } + + /// Compare endpoints for ordering. + friend bool operator>(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e2.impl_ < e1.impl_; + } + + /// Compare endpoints for ordering. + friend bool operator<=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e2 < e1); + } + + /// Compare endpoints for ordering. + friend bool operator>=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e1 < e2); + } + +private: + // The underlying generic endpoint. + asio::generic::detail::endpoint impl_; +}; + +} // namespace generic +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +#endif // ASIO_GENERIC_BASIC_ENDPOINT_HPP diff --git a/asio-1.10.6/include/asio/generic/detail/endpoint.hpp b/asio-1.10.6/include/asio/generic/detail/endpoint.hpp new file mode 100644 index 0000000..fd1513e --- /dev/null +++ b/asio-1.10.6/include/asio/generic/detail/endpoint.hpp @@ -0,0 +1,128 @@ +// +// generic/detail/endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_GENERIC_DETAIL_ENDPOINT_HPP +#define ASIO_GENERIC_DETAIL_ENDPOINT_HPP + + +#include "asio/detail/config.hpp" + +#include <cstddef> +#include "asio/detail/socket_types.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace generic { +namespace detail { + +// Helper class for implementing a generic socket endpoint. +class endpoint +{ +public: + // Default constructor. + ASIO_DECL endpoint(); + + // Construct an endpoint from the specified raw bytes. + ASIO_DECL endpoint(const void* sock_addr, + std::size_t sock_addr_size, int sock_protocol); + + // Copy constructor. + endpoint(const endpoint& other) + : data_(other.data_), + size_(other.size_), + protocol_(other.protocol_) + { + } + + // Assign from another endpoint. + endpoint& operator=(const endpoint& other) + { + data_ = other.data_; + size_ = other.size_; + protocol_ = other.protocol_; + return *this; + } + + // Get the address family associated with the endpoint. + int family() const + { + return data_.base.sa_family; + } + + // Get the socket protocol associated with the endpoint. + int protocol() const + { + return protocol_; + } + + // Get the underlying endpoint in the native type. + asio::detail::socket_addr_type* data() + { + return &data_.base; + } + + // Get the underlying endpoint in the native type. + const asio::detail::socket_addr_type* data() const + { + return &data_.base; + } + + // Get the underlying size of the endpoint in the native type. + std::size_t size() const + { + return size_; + } + + // Set the underlying size of the endpoint in the native type. + ASIO_DECL void resize(std::size_t size); + + // Get the capacity of the endpoint in the native type. + std::size_t capacity() const + { + return sizeof(asio::detail::sockaddr_storage_type); + } + + // Compare two endpoints for equality. + ASIO_DECL friend bool operator==( + const endpoint& e1, const endpoint& e2); + + // Compare endpoints for ordering. + ASIO_DECL friend bool operator<( + const endpoint& e1, const endpoint& e2); + +private: + // The underlying socket address. + union data_union + { + asio::detail::socket_addr_type base; + asio::detail::sockaddr_storage_type generic; + } data_; + + // The length of the socket address stored in the endpoint. + std::size_t size_; + + // The socket protocol associated with the endpoint. + int protocol_; + + // Initialise with a specified memory. + ASIO_DECL void init(const void* sock_addr, + std::size_t sock_addr_size, int sock_protocol); +}; + +} // namespace detail +} // namespace generic +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +# include "asio/generic/detail/impl/endpoint.ipp" + +#endif // ASIO_GENERIC_DETAIL_ENDPOINT_HPP diff --git a/asio-1.10.6/include/asio/generic/detail/impl/endpoint.ipp b/asio-1.10.6/include/asio/generic/detail/impl/endpoint.ipp new file mode 100644 index 0000000..c33f1db --- /dev/null +++ b/asio-1.10.6/include/asio/generic/detail/impl/endpoint.ipp @@ -0,0 +1,106 @@ +// +// generic/detail/impl/endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP +#define ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP + + +#include "asio/detail/config.hpp" + +#include <cstring> +#include <typeinfo> +#include "asio/detail/socket_ops.hpp" +#include "asio/detail/throw_error.hpp" +#include "asio/detail/throw_exception.hpp" +#include "asio/error.hpp" +#include "asio/generic/detail/endpoint.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace generic { +namespace detail { + +endpoint::endpoint() +{ + init(0, 0, 0); +} + +endpoint::endpoint(const void* sock_addr, + std::size_t sock_addr_size, int sock_protocol) +{ + init(sock_addr, sock_addr_size, sock_protocol); +} + +void endpoint::resize(std::size_t new_size) +{ + if (new_size > sizeof(asio::detail::sockaddr_storage_type)) + { + asio::error_code ec(asio::error::invalid_argument); + asio::detail::throw_error(ec); + } + else + { + size_ = new_size; + protocol_ = 0; + } +} + +bool operator==(const endpoint& e1, const endpoint& e2) +{ + using namespace std; // For memcmp. + return e1.size() == e2.size() && memcmp(e1.data(), e2.data(), e1.size()) == 0; +} + +bool operator<(const endpoint& e1, const endpoint& e2) +{ + if (e1.protocol() < e2.protocol()) + return true; + + if (e1.protocol() > e2.protocol()) + return false; + + using namespace std; // For memcmp. + std::size_t compare_size = e1.size() < e2.size() ? e1.size() : e2.size(); + int compare_result = memcmp(e1.data(), e2.data(), compare_size); + + if (compare_result < 0) + return true; + + if (compare_result > 0) + return false; + + return e1.size() < e2.size(); +} + +void endpoint::init(const void* sock_addr, + std::size_t sock_addr_size, int sock_protocol) +{ + if (sock_addr_size > sizeof(asio::detail::sockaddr_storage_type)) + { + asio::error_code ec(asio::error::invalid_argument); + asio::detail::throw_error(ec); + } + + using namespace std; // For memset and memcpy. + memset(&data_.generic, 0, sizeof(asio::detail::sockaddr_storage_type)); + memcpy(&data_.generic, sock_addr, sock_addr_size); + + size_ = sock_addr_size; + protocol_ = sock_protocol; +} + +} // namespace detail +} // namespace generic +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +#endif // ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP diff --git a/asio-1.10.6/include/asio/generic/stream_protocol.hpp b/asio-1.10.6/include/asio/generic/stream_protocol.hpp new file mode 100644 index 0000000..5fb13d4 --- /dev/null +++ b/asio-1.10.6/include/asio/generic/stream_protocol.hpp @@ -0,0 +1,120 @@ +// +// generic/stream_protocol.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_GENERIC_STREAM_PROTOCOL_HPP +#define ASIO_GENERIC_STREAM_PROTOCOL_HPP + + +#include "asio/detail/config.hpp" + +#include <typeinfo> +#include "asio/basic_socket_iostream.hpp" +#include "asio/basic_stream_socket.hpp" +#include "asio/detail/socket_types.hpp" +#include "asio/detail/throw_exception.hpp" +#include "asio/generic/basic_endpoint.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace generic { + +/// Encapsulates the flags needed for a generic stream-oriented socket. +/** + * The asio::generic::stream_protocol class contains flags necessary for + * stream-oriented sockets of any address family and protocol. + * + * @par Examples + * Constructing using a native address family and socket protocol: + * @code stream_protocol p(AF_INET, IPPROTO_TCP); @endcode + * Constructing from a specific protocol type: + * @code stream_protocol p(asio::ip::tcp::v4()); @endcode + * + * @par Thread Safety + * @e Distinct @e objects: Safe.@n + * @e Shared @e objects: Safe. + * + * @par Concepts: + * Protocol. + */ +class stream_protocol +{ +public: + /// Construct a protocol object for a specific address family and protocol. + stream_protocol(int address_family, int socket_protocol) + : family_(address_family), + protocol_(socket_protocol) + { + } + + /// Construct a generic protocol object from a specific protocol. + /** + * @throws @c bad_cast Thrown if the source protocol is not stream-oriented. + */ + template <typename Protocol> + stream_protocol(const Protocol& source_protocol) + : family_(source_protocol.family()), + protocol_(source_protocol.protocol()) + { + if (source_protocol.type() != type()) + { + std::bad_cast ex; + asio::detail::throw_exception(ex); + } + } + + /// Obtain an identifier for the type of the protocol. + int type() const + { + return ASIO_OS_DEF(SOCK_STREAM); + } + + /// Obtain an identifier for the protocol. + int protocol() const + { + return protocol_; + } + + /// Obtain an identifier for the protocol family. + int family() const + { + return family_; + } + + /// Compare two protocols for equality. + friend bool operator==(const stream_protocol& p1, const stream_protocol& p2) + { + return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_; + } + + /// Compare two protocols for inequality. + friend bool operator!=(const stream_protocol& p1, const stream_protocol& p2) + { + return !(p1 == p2); + } + + /// The type of an endpoint. + typedef basic_endpoint<stream_protocol> endpoint; + + /// The generic socket type. + typedef basic_stream_socket<stream_protocol> socket; + + +private: + int family_; + int protocol_; +}; + +} // namespace generic +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +#endif // ASIO_GENERIC_STREAM_PROTOCOL_HPP diff --git a/asio-1.10.6/include/asio/local/basic_endpoint.hpp b/asio-1.10.6/include/asio/local/basic_endpoint.hpp new file mode 100644 index 0000000..0728f61 --- /dev/null +++ b/asio-1.10.6/include/asio/local/basic_endpoint.hpp @@ -0,0 +1,222 @@ +// +// local/basic_endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Derived from a public domain implementation written by Daniel Casimiro. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_LOCAL_BASIC_ENDPOINT_HPP +#define ASIO_LOCAL_BASIC_ENDPOINT_HPP + + +#include "asio/detail/config.hpp" + + +#include "asio/local/detail/endpoint.hpp" + + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace local { + +/// Describes an endpoint for a UNIX socket. +/** + * The asio::local::basic_endpoint class template describes an endpoint + * that may be associated with a particular UNIX socket. + * + * @par Thread Safety + * @e Distinct @e objects: Safe.@n + * @e Shared @e objects: Unsafe. + * + * @par Concepts: + * Endpoint. + */ +template <typename Protocol> +class basic_endpoint +{ +public: + /// The protocol type associated with the endpoint. + typedef Protocol protocol_type; + + /// The type of the endpoint structure. This type is dependent on the + /// underlying implementation of the socket layer. + typedef asio::detail::socket_addr_type data_type; + + /// Default constructor. + basic_endpoint() + { + } + + /// Construct an endpoint using the specified path name. + basic_endpoint(const char* path_name) + : impl_(path_name) + { + } + + /// Construct an endpoint using the specified path name. + basic_endpoint(const std::string& path_name) + : impl_(path_name) + { + } + + /// Copy constructor. + basic_endpoint(const basic_endpoint& other) + : impl_(other.impl_) + { + } + + /// Move constructor. + basic_endpoint(basic_endpoint&& other) + : impl_(other.impl_) + { + } + + /// Assign from another endpoint. + basic_endpoint& operator=(const basic_endpoint& other) + { + impl_ = other.impl_; + return *this; + } + + /// Move-assign from another endpoint. + basic_endpoint& operator=(basic_endpoint&& other) + { + impl_ = other.impl_; + return *this; + } + + /// The protocol associated with the endpoint. + protocol_type protocol() const + { + return protocol_type(); + } + + /// Get the underlying endpoint in the native type. + data_type* data() + { + return impl_.data(); + } + + /// Get the underlying endpoint in the native type. + const data_type* data() const + { + return impl_.data(); + } + + /// Get the underlying size of the endpoint in the native type. + std::size_t size() const + { + return impl_.size(); + } + + /// Set the underlying size of the endpoint in the native type. + void resize(std::size_t new_size) + { + impl_.resize(new_size); + } + + /// Get the capacity of the endpoint in the native type. + std::size_t capacity() const + { + return impl_.capacity(); + } + + /// Get the path associated with the endpoint. + std::string path() const + { + return impl_.path(); + } + + /// Set the path associated with the endpoint. + void path(const char* p) + { + impl_.path(p); + } + + /// Set the path associated with the endpoint. + void path(const std::string& p) + { + impl_.path(p); + } + + /// Compare two endpoints for equality. + friend bool operator==(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e1.impl_ == e2.impl_; + } + + /// Compare two endpoints for inequality. + friend bool operator!=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e1.impl_ == e2.impl_); + } + + /// Compare endpoints for ordering. + friend bool operator<(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e1.impl_ < e2.impl_; + } + + /// Compare endpoints for ordering. + friend bool operator>(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return e2.impl_ < e1.impl_; + } + + /// Compare endpoints for ordering. + friend bool operator<=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e2 < e1); + } + + /// Compare endpoints for ordering. + friend bool operator>=(const basic_endpoint<Protocol>& e1, + const basic_endpoint<Protocol>& e2) + { + return !(e1 < e2); + } + +private: + // The underlying UNIX domain endpoint. + asio::local::detail::endpoint impl_; +}; + +/// Output an endpoint as a string. +/** + * Used to output a human-readable string for a specified endpoint. + * + * @param os The output stream to which the string will be written. + * + * @param endpoint The endpoint to be written. + * + * @return The output stream. + * + * @relates asio::local::basic_endpoint + */ +template <typename Elem, typename Traits, typename Protocol> +std::basic_ostream<Elem, Traits>& operator<<( + std::basic_ostream<Elem, Traits>& os, + const basic_endpoint<Protocol>& endpoint) +{ + os << endpoint.path(); + return os; +} + +} // namespace local +} // namespace asio + +#include "asio/detail/pop_options.hpp" + + // || defined(GENERATING_DOCUMENTATION) + +#endif // ASIO_LOCAL_BASIC_ENDPOINT_HPP diff --git a/asio-1.10.6/include/asio/local/detail/endpoint.hpp b/asio-1.10.6/include/asio/local/detail/endpoint.hpp new file mode 100644 index 0000000..343f0a9 --- /dev/null +++ b/asio-1.10.6/include/asio/local/detail/endpoint.hpp @@ -0,0 +1,126 @@ +// +// local/detail/endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Derived from a public domain implementation written by Daniel Casimiro. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_LOCAL_DETAIL_ENDPOINT_HPP +#define ASIO_LOCAL_DETAIL_ENDPOINT_HPP + + +#include "asio/detail/config.hpp" + + +#include <cstddef> +#include <string> +#include "asio/detail/socket_types.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace local { +namespace detail { + +// Helper class for implementing a UNIX domain endpoint. +class endpoint +{ +public: + // Default constructor. + ASIO_DECL endpoint(); + + // Construct an endpoint using the specified path name. + ASIO_DECL endpoint(const char* path_name); + + // Construct an endpoint using the specified path name. + ASIO_DECL endpoint(const std::string& path_name); + + // Copy constructor. + endpoint(const endpoint& other) + : data_(other.data_), + path_length_(other.path_length_) + { + } + + // Assign from another endpoint. + endpoint& operator=(const endpoint& other) + { + data_ = other.data_; + path_length_ = other.path_length_; + return *this; + } + + // Get the underlying endpoint in the native type. + asio::detail::socket_addr_type* data() + { + return &data_.base; + } + + // Get the underlying endpoint in the native type. + const asio::detail::socket_addr_type* data() const + { + return &data_.base; + } + + // Get the underlying size of the endpoint in the native type. + std::size_t size() const + { + return path_length_ + + offsetof(asio::detail::sockaddr_un_type, sun_path); + } + + // Set the underlying size of the endpoint in the native type. + ASIO_DECL void resize(std::size_t size); + + // Get the capacity of the endpoint in the native type. + std::size_t capacity() const + { + return sizeof(asio::detail::sockaddr_un_type); + } + + // Get the path associated with the endpoint. + ASIO_DECL std::string path() const; + + // Set the path associated with the endpoint. + ASIO_DECL void path(const char* p); + + // Set the path associated with the endpoint. + ASIO_DECL void path(const std::string& p); + + // Compare two endpoints for equality. + ASIO_DECL friend bool operator==( + const endpoint& e1, const endpoint& e2); + + // Compare endpoints for ordering. + ASIO_DECL friend bool operator<( + const endpoint& e1, const endpoint& e2); + +private: + // The underlying UNIX socket address. + union data_union + { + asio::detail::socket_addr_type base; + asio::detail::sockaddr_un_type local; + } data_; + + // The length of the path associated with the endpoint. + std::size_t path_length_; + + // Initialise with a specified path. + ASIO_DECL void init(const char* path, std::size_t path_length); +}; + +} // namespace detail +} // namespace local +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +# include "asio/local/detail/impl/endpoint.ipp" + + +#endif // ASIO_LOCAL_DETAIL_ENDPOINT_HPP diff --git a/asio-1.10.6/include/asio/local/detail/impl/endpoint.ipp b/asio-1.10.6/include/asio/local/detail/impl/endpoint.ipp new file mode 100644 index 0000000..5379398 --- /dev/null +++ b/asio-1.10.6/include/asio/local/detail/impl/endpoint.ipp @@ -0,0 +1,123 @@ +// +// local/detail/impl/endpoint.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Derived from a public domain implementation written by Daniel Casimiro. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_LOCAL_DETAIL_IMPL_ENDPOINT_IPP +#define ASIO_LOCAL_DETAIL_IMPL_ENDPOINT_IPP + + +#include "asio/detail/config.hpp" + + +#include <cstring> +#include "asio/detail/socket_ops.hpp" +#include "asio/detail/throw_error.hpp" +#include "asio/error.hpp" +#include "asio/local/detail/endpoint.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace local { +namespace detail { + +endpoint::endpoint() +{ + init("", 0); +} + +endpoint::endpoint(const char* path_name) +{ + using namespace std; // For strlen. + init(path_name, strlen(path_name)); +} + +endpoint::endpoint(const std::string& path_name) +{ + init(path_name.data(), path_name.length()); +} + +void endpoint::resize(std::size_t new_size) +{ + if (new_size > sizeof(asio::detail::sockaddr_un_type)) + { + asio::error_code ec(asio::error::invalid_argument); + asio::detail::throw_error(ec); + } + else if (new_size == 0) + { + path_length_ = 0; + } + else + { + path_length_ = new_size + - offsetof(asio::detail::sockaddr_un_type, sun_path); + + // The path returned by the operating system may be NUL-terminated. + if (path_length_ > 0 && data_.local.sun_path[path_length_ - 1] == 0) + --path_length_; + } +} + +std::string endpoint::path() const +{ + return std::string(data_.local.sun_path, path_length_); +} + +void endpoint::path(const char* p) +{ + using namespace std; // For strlen. + init(p, strlen(p)); +} + +void endpoint::path(const std::string& p) +{ + init(p.data(), p.length()); +} + +bool operator==(const endpoint& e1, const endpoint& e2) +{ + return e1.path() == e2.path(); +} + +bool operator<(const endpoint& e1, const endpoint& e2) +{ + return e1.path() < e2.path(); +} + +void endpoint::init(const char* path_name, std::size_t path_length) +{ + if (path_length > sizeof(data_.local.sun_path) - 1) + { + // The buffer is not large enough to store this address. + asio::error_code ec(asio::error::name_too_long); + asio::detail::throw_error(ec); + } + + using namespace std; // For memcpy. + data_.local = asio::detail::sockaddr_un_type(); + data_.local.sun_family = AF_UNIX; + memcpy(data_.local.sun_path, path_name, path_length); + path_length_ = path_length; + + // NUL-terminate normal path names. Names that start with a NUL are in the + // UNIX domain protocol's "abstract namespace" and are not NUL-terminated. + if (path_length > 0 && data_.local.sun_path[0] == 0) + data_.local.sun_path[path_length] = 0; +} + +} // namespace detail +} // namespace local +} // namespace asio + +#include "asio/detail/pop_options.hpp" + + +#endif // ASIO_LOCAL_DETAIL_IMPL_ENDPOINT_IPP diff --git a/asio-1.10.6/include/asio/local/stream_protocol.hpp b/asio-1.10.6/include/asio/local/stream_protocol.hpp new file mode 100644 index 0000000..142a80d --- /dev/null +++ b/asio-1.10.6/include/asio/local/stream_protocol.hpp @@ -0,0 +1,80 @@ +// +// local/stream_protocol.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_LOCAL_STREAM_PROTOCOL_HPP +#define ASIO_LOCAL_STREAM_PROTOCOL_HPP + + +#include "asio/detail/config.hpp" + + +#include "asio/basic_socket_acceptor.hpp" +#include "asio/basic_socket_iostream.hpp" +#include "asio/basic_stream_socket.hpp" +#include "asio/detail/socket_types.hpp" +#include "asio/local/basic_endpoint.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace local { + +/// Encapsulates the flags needed for stream-oriented UNIX sockets. +/** + * The asio::local::stream_protocol class contains flags necessary for + * stream-oriented UNIX domain sockets. + * + * @par Thread Safety + * @e Distinct @e objects: Safe.@n + * @e Shared @e objects: Safe. + * + * @par Concepts: + * Protocol. + */ +class stream_protocol +{ +public: + /// Obtain an identifier for the type of the protocol. + int type() const + { + return SOCK_STREAM; + } + + /// Obtain an identifier for the protocol. + int protocol() const + { + return 0; + } + + /// Obtain an identifier for the protocol family. + int family() const + { + return AF_UNIX; + } + + /// The type of a UNIX domain endpoint. + typedef basic_endpoint<stream_protocol> endpoint; + + /// The UNIX domain socket type. + typedef basic_stream_socket<stream_protocol> socket; + + /// The UNIX domain acceptor type. + typedef basic_socket_acceptor<stream_protocol> acceptor; + +}; + +} // namespace local +} // namespace asio + +#include "asio/detail/pop_options.hpp" + + // || defined(GENERATING_DOCUMENTATION) + +#endif // ASIO_LOCAL_STREAM_PROTOCOL_HPP diff --git a/support/android/asio/asio.hpp b/support/android/asio/asio.hpp index ca7cd2f..6698fd7 100644 --- a/support/android/asio/asio.hpp +++ b/support/android/asio/asio.hpp @@ -42,6 +42,8 @@ #include "asio/error_code.hpp" #include "asio/io_service.hpp" #include "asio/ip/tcp.hpp" +#include "asio/generic/stream_protocol.hpp" +#include "asio/local/stream_protocol.hpp" #include "asio/read.hpp" #include "asio/socket_base.hpp" #include "asio/system_error.hpp" diff --git a/support/android/asio/asio_defines.txt b/support/android/asio/asio_defines.txt index e00ca1e..6218ff5 100644 --- a/support/android/asio/asio_defines.txt +++ b/support/android/asio/asio_defines.txt @@ -67,14 +67,14 @@ #undef ASIO_HAS_TIMERFD #define ASIO_HAS_THREADS // We are not using asio for iostream, nor serial ports, nor posix file -// descriptiors, nor with unix sockets +// descriptiors #define ASIO_NO_IOSTREAM #define ASIO_DISABLE_SERIAL_PORT #undef ASIO_HAS_SERIAL_PORT #undef ASIO_HAS_POSIX_STREAM_DESCRIPTOR #define ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR -#undef ASIO_HAS_LOCAL_SOCKETS -#define ASIO_DISABLE_LOCAL_SOCKETS +#define ASIO_HAS_LOCAL_SOCKETS +#undef ASIO_DISABLE_LOCAL_SOCKETS // windows-only features #undef ASIO_HAS_IOCP #undef ASIO_HAS_WINDOWS_OBJECT_HANDLE diff --git a/upstream/asio/stub/asio.hpp b/upstream/asio/stub/asio.hpp index 84a0ea4..1fd3b0c 100644 --- a/upstream/asio/stub/asio.hpp +++ b/upstream/asio/stub/asio.hpp @@ -37,6 +37,10 @@ #include <system_error> +#include <netinet/in.h> + +#define ASIO_OS_DEF(x) (x) + namespace asio { struct dummy_base @@ -46,7 +50,27 @@ struct dummy_base { } void set_option(const dummy_base &) const {}; + int protocol() const { return 0; } +}; +struct endpoint_base : dummy_base +{ + using dummy_base::dummy_base; + + dummy_base protocol() const { return {}; }; }; + +template <typename T> +struct basic_socket_acceptor : dummy_base +{ + using dummy_base::dummy_base; + + using reuse_address = dummy_base; + void open(const dummy_base &) const {}; + void bind(const dummy_base &) const {}; + void listen() const {}; + void async_accept(const dummy_base &, const dummy_base &) const {}; +}; + inline bool write(const dummy_base &, const dummy_base &, const dummy_base &) { return true; @@ -76,6 +100,10 @@ struct socket_base : dummy_base using linger = dummy_base; using enable_connection_aborted = dummy_base; void close() const {}; + + const endpoint_base &local_endpoint() const { return base; } + + endpoint_base base; }; bool write(const dummy_base &, const dummy_base &, const dummy_base &); @@ -95,23 +123,23 @@ namespace tcp { using v6 = dummy_base; using no_delay = dummy_base; +using endpoint = endpoint_base; using socket = socket_base; -struct endpoint : dummy_base -{ - using dummy_base::dummy_base; +using acceptor = basic_socket_acceptor<void>; +} +} - dummy_base protocol() const { return {}; }; -}; -struct acceptor : dummy_base +namespace generic { - using dummy_base::dummy_base; - - using reuse_address = dummy_base; - void open(const dummy_base &) const {}; - void bind(const dummy_base &) const {}; - void listen() const {}; - void async_accept(const dummy_base &, const dummy_base &) const {}; +struct stream_protocol +{ + using endpoint = endpoint_base; + using socket = socket_base; }; -} +}; + +namespace local +{ +using stream_protocol = generic::stream_protocol; } } diff --git a/upstream/parameter/ParameterFrameworkConfiguration.cpp b/upstream/parameter/ParameterFrameworkConfiguration.cpp index bf735fd..1f18f45 100644 --- a/upstream/parameter/ParameterFrameworkConfiguration.cpp +++ b/upstream/parameter/ParameterFrameworkConfiguration.cpp @@ -53,10 +53,10 @@ bool CParameterFrameworkConfiguration::isTuningAllowed() const return _bTuningAllowed; } -// Server port -uint16_t CParameterFrameworkConfiguration::getServerPort() const +// Server bind address +const std::string &CParameterFrameworkConfiguration::getServerBindAddress() const { - return _uiServerPort; + return _bindAddress; } // From IXmlSink @@ -70,7 +70,7 @@ bool CParameterFrameworkConfiguration::fromXml(const CXmlElement &xmlElement, xmlElement.getAttribute("TuningAllowed", _bTuningAllowed); // Server port - xmlElement.getAttribute("ServerPort", _uiServerPort); + xmlElement.getAttribute("ServerPort", _bindAddress); // Base return base::fromXml(xmlElement, serializingContext); diff --git a/upstream/parameter/ParameterFrameworkConfiguration.h b/upstream/parameter/ParameterFrameworkConfiguration.h index 8972beb..83bb49f 100644 --- a/upstream/parameter/ParameterFrameworkConfiguration.h +++ b/upstream/parameter/ParameterFrameworkConfiguration.h @@ -43,7 +43,7 @@ public: bool isTuningAllowed() const; // Server port - uint16_t getServerPort() const; + const std::string &getServerBindAddress() const; // From IXmlSink bool fromXml(const CXmlElement &xmlElement, @@ -58,5 +58,5 @@ private: // Tuning allowed bool _bTuningAllowed{false}; // Server port - uint16_t _uiServerPort{0}; + std::string _bindAddress; }; diff --git a/upstream/parameter/ParameterMgr.cpp b/upstream/parameter/ParameterMgr.cpp index debf81d..d515af0 100644 --- a/upstream/parameter/ParameterMgr.cpp +++ b/upstream/parameter/ParameterMgr.cpp @@ -129,7 +129,7 @@ using namespace core; // Used for remote processor server creation typedef IRemoteProcessorServerInterface *(*CreateRemoteProcessorServer)( - uint16_t uiPort, IRemoteCommandHandler *pCommandHandler); + std::string bindAddress, IRemoteCommandHandler *pCommandHandler); // Config File System looks normally like this: // --------------------------------------------- @@ -2852,11 +2852,12 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError) return true; } - auto port = getConstFrameworkConfiguration()->getServerPort(); + auto bindAddress = getConstFrameworkConfiguration()->getServerBindAddress(); try { // The ownership of remoteComandHandler is given to Bg remote processor server. - _pRemoteProcessorServer = new BackgroundRemoteProcessorServer(port, createCommandHandler()); + _pRemoteProcessorServer = + new BackgroundRemoteProcessorServer(bindAddress, createCommandHandler()); } catch (std::runtime_error &e) { strError = string("ParameterMgr: Unable to create Remote Processor Server: ") + e.what(); return false; @@ -2869,11 +2870,11 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError) if (!_pRemoteProcessorServer->start(strError)) { ostringstream oss; - oss << "ParameterMgr: Unable to start remote processor server on port " << port; + oss << "ParameterMgr: Unable to start remote processor server on " << bindAddress; strError = oss.str() + ": " + strError; return false; } - info() << "Remote Processor Server started on port " << port; + info() << "Remote Processor Server started on " << bindAddress; return true; } diff --git a/upstream/remote-process/main.cpp b/upstream/remote-process/main.cpp index 3ebaa86..ad94dc3 100644 --- a/upstream/remote-process/main.cpp +++ b/upstream/remote-process/main.cpp @@ -37,10 +37,12 @@ #include "RequestMessage.h" #include "AnswerMessage.h" #include "Socket.h" +#include "convert.hpp" using namespace std; -bool sendAndDisplayCommand(asio::ip::tcp::socket &socket, CRequestMessage &requestMessage) +bool sendAndDisplayCommand(asio::generic::stream_protocol::socket &socket, + CRequestMessage &requestMessage) { string strError; @@ -72,41 +74,111 @@ bool sendAndDisplayCommand(asio::ip::tcp::socket &socket, CRequestMessage &reque return true; } -// hostname port command [argument[s]] +int usage(const std::string &command, const std::string &error) +{ + if (not error.empty()) { + cerr << error << endl; + } + cerr << "Usage: " << endl; + cerr << "Send a single command:" << endl; + cerr << "\t" << command + << " <hostname port|<protocol>://<host:port|port_name>> <command> [argument[s]]" << endl; + + return 1; +} + +// <hostname port|path> command [argument[s]] // or -// hostname port < commands +// <hostname port|path> < commands int main(int argc, char *argv[]) { - // Enough args? - if (argc < 4) { + int commandPos; - cerr << "Missing arguments" << endl; - cerr << "Usage: " << endl; - cerr << "Send a single command:" << endl; - cerr << "\t" << argv[0] << " hostname port command [argument[s]]" << endl; - - return 1; + // Enough args? + if (argc < 3) { + return usage(argv[0], "Missing arguments"); } - using asio::ip::tcp; asio::io_service io_service; - tcp::resolver resolver(io_service); + asio::generic::stream_protocol::socket connectionSocket(io_service); - tcp::socket connectionSocket(io_service); - - string host{argv[1]}; - string port{argv[2]}; + bool isInet = false; + string port; + string host; try { - asio::connect(connectionSocket, resolver.resolve(tcp::resolver::query(host, port))); + // backward compatibility: tcp port only refered by its value + uint16_t testConverter; + if (convertTo({argv[2]}, testConverter)) { + isInet = true; + port = argv[2]; + host = argv[1]; + if (argc <= 3) { + return usage(argv[0], "Missing arguments"); + } + commandPos = 3; + } else { + commandPos = 2; + string endPortArg{argv[1]}; + std::string protocol; + + const std::string tcpProtocol{"tcp"}; + const std::string unixProtocol{"unix"}; + const std::vector<std::string> supportedProtocols{ tcpProtocol, unixProtocol }; + const std::string protocolDelimiter{"://"}; + + size_t protocolDelPos = endPortArg.find(protocolDelimiter); + if (protocolDelPos == std::string::npos) { + return usage(argv[0], "Invalid socket endpoint, missing " + protocolDelimiter); + } + protocol = endPortArg.substr(0, protocolDelPos); + + if (std::find(begin(supportedProtocols), end(supportedProtocols), protocol) == + end(supportedProtocols)) { + return usage(argv[0], "Invalid socket protocol " + protocol); + } + isInet = (endPortArg.find(tcpProtocol) != std::string::npos); + if (isInet) { + size_t portDelPos = endPortArg.find(':', protocolDelPos + protocolDelimiter.size()); + if (portDelPos == std::string::npos) { + return usage(argv[0], "Invalid tcp endpoint" + endPortArg); + } + host = endPortArg.substr(protocolDelPos + protocolDelimiter.size(), + portDelPos - (protocolDelPos + protocolDelimiter.size())); + port = endPortArg.substr(portDelPos + 1); + } else { + port = endPortArg.substr(protocolDelPos + protocolDelimiter.size()); + } + } + if (isInet) { + asio::ip::tcp::resolver resolver(io_service); + asio::ip::tcp::socket tcpSocket(io_service); + + asio::connect(tcpSocket, resolver.resolve(asio::ip::tcp::resolver::query(host, port))); + connectionSocket = std::move(tcpSocket); + } else { + asio::generic::stream_protocol::socket socket(io_service); + asio::generic::stream_protocol::endpoint endpoint = + asio::local::stream_protocol::endpoint(port); + socket.connect(endpoint); + connectionSocket = std::move(socket); + } + } catch (const asio::system_error &e) { - cerr << "Connection to '" << host << ":" << port << "' failed: " << e.what() << endl; + string endpoint; + + if (isInet) { + endpoint = string("tcp://") + host + ":" + port; + } else { /* other supported protocols */ + endpoint = argv[1]; + } + cerr << "Connection to '" << endpoint << "' failed: " << e.what() << endl; return 1; } // Create command message - CRequestMessage requestMessage(argv[3]); + CRequestMessage requestMessage(argv[commandPos]); // Add arguments - for (int arg = 4; arg < argc; arg++) { + for (int arg = commandPos + 1; arg < argc; arg++) { requestMessage.addArgument(argv[arg]); } diff --git a/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp b/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp index 0820786..b880107 100644 --- a/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp +++ b/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp @@ -31,8 +31,8 @@ #include "RemoteProcessorServer.h" BackgroundRemoteProcessorServer::BackgroundRemoteProcessorServer( - uint16_t uiPort, std::unique_ptr<IRemoteCommandHandler> &&commandHandler) - : _server(new CRemoteProcessorServer(uiPort)), mCommandHandler(std::move(commandHandler)) + std::string bindAddress, std::unique_ptr<IRemoteCommandHandler> &&commandHandler) + : _server(new CRemoteProcessorServer(bindAddress)), mCommandHandler(std::move(commandHandler)) { } diff --git a/upstream/remote-processor/BackgroundRemoteProcessorServer.h b/upstream/remote-processor/BackgroundRemoteProcessorServer.h index 221c08b..22c0242 100644 --- a/upstream/remote-processor/BackgroundRemoteProcessorServer.h +++ b/upstream/remote-processor/BackgroundRemoteProcessorServer.h @@ -40,7 +40,7 @@ class REMOTE_PROCESSOR_EXPORT BackgroundRemoteProcessorServer final : public IRemoteProcessorServerInterface { public: - BackgroundRemoteProcessorServer(uint16_t uiPort, + BackgroundRemoteProcessorServer(std::string bindAddress, std::unique_ptr<IRemoteCommandHandler> &&commandHandler); ~BackgroundRemoteProcessorServer() override; diff --git a/upstream/remote-processor/Message.cpp b/upstream/remote-processor/Message.cpp index 66154ec..5faecc0 100644 --- a/upstream/remote-processor/Message.cpp +++ b/upstream/remote-processor/Message.cpp @@ -129,7 +129,7 @@ size_t CMessage::getRemainingDataSize() const // Send/Receive CMessage::Result CMessage::serialize(Socket &&socket, bool bOut, string &strError) { - asio::ip::tcp::socket &asioSocket = socket.get(); + auto &asioSocket = socket.get(); if (bOut) { asio::error_code ec; diff --git a/upstream/remote-processor/RemoteProcessorServer.cpp b/upstream/remote-processor/RemoteProcessorServer.cpp index d3fefdd..de7447e 100644 --- a/upstream/remote-processor/RemoteProcessorServer.cpp +++ b/upstream/remote-processor/RemoteProcessorServer.cpp @@ -32,15 +32,17 @@ #include <memory> #include <assert.h> #include <string.h> +#include <unistd.h> #include "RequestMessage.h" #include "AnswerMessage.h" #include "RemoteCommandHandler.h" #include "Socket.h" +#include "convert.hpp" using std::string; -CRemoteProcessorServer::CRemoteProcessorServer(uint16_t uiPort) - : _uiPort(uiPort), _io_service(), _acceptor(_io_service), _socket(_io_service) +CRemoteProcessorServer::CRemoteProcessorServer(std::string bindAddress) + : _bindAddress(bindAddress), _io_service(), _acceptor(_io_service), _socket(_io_service) { } @@ -55,18 +57,71 @@ bool CRemoteProcessorServer::start(string &error) using namespace asio; try { - ip::tcp::endpoint endpoint(ip::tcp::v6(), _uiPort); + generic::stream_protocol::endpoint endpoint; + uint16_t port; + std::string endpointName; + bool isInet; + + // For backward compatibility, tcp port referred by its value only + if (convertTo(_bindAddress, port)) { + isInet = true; + } else { + // required form is <protocol>://<host:port|port_name> + const std::string tcpProtocol{"tcp"}; + const std::string unixProtocol{"unix"}; + const std::vector<std::string> supportedProtocols{ tcpProtocol, unixProtocol }; + const std::string protocolDel{"://"}; + + size_t protocolDelPos = _bindAddress.find(protocolDel); + if (protocolDelPos == std::string::npos) { + error = "bindaddress " + _bindAddress + " ill formed, missing " + protocolDel; + return false; + } + std::string protocol = _bindAddress.substr(0, protocolDelPos); + + if (std::find(begin(supportedProtocols), end(supportedProtocols), protocol) == + end(supportedProtocols)) { + error = "bindaddress " + _bindAddress + " has invalid protocol " + protocol; + return false; + } + isInet = (_bindAddress.find(tcpProtocol) != std::string::npos); + if (isInet) { + size_t portDelPos = _bindAddress.find(':', protocolDelPos + protocolDel.size()); + if (portDelPos == std::string::npos) { + error = "bindaddress " + _bindAddress + " ill formed, missing " + ":"; + return false; + } + std::string portLiteral{_bindAddress.substr(portDelPos + 1)}; + if (!convertTo(portLiteral, port)) { + error = "bindaddress " + _bindAddress + " port " + portLiteral + " ill formed"; + return false; + } + } else { + endpointName = _bindAddress.substr(protocolDelPos + protocolDel.size()); + } + } + + if (isInet) { + endpoint = ip::tcp::endpoint(ip::tcp::v6(), port); + } else { + endpoint = local::stream_protocol::endpoint(endpointName); + } _acceptor.open(endpoint.protocol()); - _acceptor.set_option(ip::tcp::acceptor::reuse_address(true)); - _acceptor.set_option(asio::socket_base::linger(true, 0)); + if (endpoint.protocol().protocol() == ASIO_OS_DEF(IPPROTO_TCP)) { + _acceptor.set_option(ip::tcp::acceptor::reuse_address(true)); + } else if (endpoint.protocol().protocol() == AF_UNSPEC) { + // In case of reuse, remote it first + unlink(endpointName.c_str()); + } + _acceptor.set_option(socket_base::linger(true, 0)); _acceptor.set_option(socket_base::enable_connection_aborted(true)); _acceptor.bind(endpoint); _acceptor.listen(); } catch (std::exception &e) { - error = "Unable to listen on port " + std::to_string(_uiPort) + ": " + e.what(); + error = "Unable to listen on " + _bindAddress + ": " + e.what(); return false; } @@ -88,7 +143,10 @@ void CRemoteProcessorServer::acceptRegister(IRemoteCommandHandler &commandHandle return; } - _socket.set_option(asio::ip::tcp::no_delay(true)); + const auto &endpoint = _socket.local_endpoint(); + if (endpoint.protocol().protocol() == ASIO_OS_DEF(IPPROTO_TCP)) { + _socket.set_option(asio::ip::tcp::no_delay(true)); + } handleNewConnection(commandHandler); _socket.close(); diff --git a/upstream/remote-processor/RemoteProcessorServer.h b/upstream/remote-processor/RemoteProcessorServer.h index 2da0113..7a2f739 100644 --- a/upstream/remote-processor/RemoteProcessorServer.h +++ b/upstream/remote-processor/RemoteProcessorServer.h @@ -31,7 +31,7 @@ #include "remote_processor_export.h" -#include <stdint.h> +#include <string> #include "RemoteProcessorServerInterface.h" #include <asio.hpp> @@ -40,7 +40,7 @@ class IRemoteCommandHandler; class REMOTE_PROCESSOR_EXPORT CRemoteProcessorServer : public IRemoteProcessorServerInterface { public: - CRemoteProcessorServer(uint16_t uiPort); + CRemoteProcessorServer(std::string bindAddress); virtual ~CRemoteProcessorServer(); // State @@ -54,10 +54,10 @@ private: // New connection void handleNewConnection(IRemoteCommandHandler &commandHandler); - // Port number - uint16_t _uiPort; + // Bind address + std::string _bindAddress; asio::io_service _io_service; - asio::ip::tcp::acceptor _acceptor; - asio::ip::tcp::socket _socket; + asio::basic_socket_acceptor<asio::generic::stream_protocol> _acceptor; + asio::generic::stream_protocol::socket _socket; }; diff --git a/upstream/remote-processor/Socket.h b/upstream/remote-processor/Socket.h index 020750b..091d1cb 100644 --- a/upstream/remote-processor/Socket.h +++ b/upstream/remote-processor/Socket.h @@ -29,19 +29,19 @@ */ #include <asio.hpp> -/** Wraps and hides asio::ip::tcp::socket +/** Wraps and hides asio::generic::stream_protocol::socket * - * asio::ip::tcp::socket cannot be forward-declared because it is an + * asio::generic::stream_protocol::socket cannot be forward-declared because it is an * inner-class. This class wraps the asio class in order for it to be * forward-declared and avoid it to leak in client interfaces. */ class Socket { public: - Socket(asio::ip::tcp::socket &socket) : mSocket(socket) {} + Socket(asio::generic::stream_protocol::socket &socket) : mSocket(socket) {} - asio::ip::tcp::socket &get() { return mSocket; } + asio::generic::stream_protocol::socket &get() { return mSocket; } private: - asio::ip::tcp::socket &mSocket; + asio::generic::stream_protocol::socket &mSocket; }; diff --git a/upstream/schemas/ParameterFrameworkConfiguration.xsd b/upstream/schemas/ParameterFrameworkConfiguration.xsd index 522b806..6cc97a5 100644 --- a/upstream/schemas/ParameterFrameworkConfiguration.xsd +++ b/upstream/schemas/ParameterFrameworkConfiguration.xsd @@ -33,7 +33,7 @@ <xs:element name="SettingsConfiguration" type="SettingsConfigurationType" minOccurs="0"/> </xs:sequence> <xs:attribute name="SystemClassName" use="required" type="xs:NMTOKEN"/> - <xs:attribute name="ServerPort" use="required" type="xs:positiveInteger"/> + <xs:attribute name="ServerPort" use="required" type="xs:string"/> <xs:attribute name="TuningAllowed" use="required" type="xs:boolean"/> </xs:complexType> </xs:element> diff --git a/upstream/schemas/README.md b/upstream/schemas/README.md index f634d8c..4c1efb1 100644 --- a/upstream/schemas/README.md +++ b/upstream/schemas/README.md @@ -38,7 +38,7 @@ Attributes of `ParameterFrameworkConfiguration` are: - The `SystemClass` name (for consistency check) - `TuningAllowed` (whether the parameter-framework listens for commands) -- The `ServerPort` on which the parameter-framework listens if +- The `ServerPort` bind Address (PATH or TCP port) on which the parameter-framework listens if `TuningAllowed=true`. ## SystemClass.xsd diff --git a/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py b/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py index d75084c..714a41d 100644 --- a/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py +++ b/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py @@ -74,18 +74,18 @@ class Pfw(RemoteCli): class Hal(RemoteCli): # Arbitrary choosen port, try to avoid conflicting with IANA registered ports - testPlatformPort = 18444 - platform_command = ["remote-process", "localhost", str(testPlatformPort)] + testPlatformBindAddress = "18444" + platform_command = ["remote-process", "localhost", testPlatformBindAddress] def __init__(self, pfw): self.pfw = pfw # Starts the HAL exe def startHal(self): - cmd= ["test-platform", os.environ["PFW_TEST_CONFIGURATION"], str(self.testPlatformPort)] + cmd= ["test-platform", os.environ["PFW_TEST_CONFIGURATION"], self.testPlatformBindAddress] self.setRemoteProcess(subprocess.Popen(cmd)) # Wait for the test-platform listening socket - while socket.socket().connect_ex(("localhost", self.testPlatformPort)) != 0: + while socket.socket().connect_ex(("localhost", int(self.testPlatformBindAddress))) != 0: assert self.remoteProcess.poll() == None, "Test platform has failed to start. Return code: %s" % self.remoteProcess.returncode time.sleep(0.01) diff --git a/upstream/test/functional-tests/AutoSync.cpp b/upstream/test/functional-tests/AutoSync.cpp index d23c0f7..c075700 100644 --- a/upstream/test/functional-tests/AutoSync.cpp +++ b/upstream/test/functional-tests/AutoSync.cpp @@ -30,11 +30,14 @@ #include "Config.hpp" #include "ParameterFramework.hpp" +#include "DynamicLibrary.hpp" #include <SubsystemObject.h> #include <IntrospectionEntryPoint.h> #include "Test.hpp" #include <catch.hpp> #include <string> +#include <iostream> +#include "Memory.hpp" using std::string; @@ -43,7 +46,13 @@ namespace parameterFramework struct BoolPF : public ParameterFramework { - BoolPF() : ParameterFramework{createConfig()} {} + BoolPF() : ParameterFramework{createConfig()} { + + mDynamicLibrary = ::utility::make_unique<DynamicLibrary>(mSubsystemPath); + REQUIRE(mDynamicLibrary != nullptr); + mGetParamFunc = mDynamicLibrary->getSymbol<GetParamFunc>("getParameterValue"); + REQUIRE(mGetParamFunc != nullptr); + } /** Set the boolean parameter value within the "Conf" configuration, * which is always applicable. */ @@ -53,14 +62,18 @@ struct BoolPF : public ParameterFramework setConfigurationParameter("Domain", "Conf", "/test/test/param", valueStr); } + bool getParameterValue() + { + return mGetParamFunc(); + } + private: static Config createConfig() { Config config; config.instances = R"(<BooleanParameter Name="param" Mapping="Object"/>)"; - config.plugins = {{"", {"introspection-subsystem"}}}; + config.plugins = {{PLUGIN_PATH, {PLUGIN_NAME}}}; config.subsystemType = "INTROSPECTION"; - config.domains = R"(<ConfigurableDomain Name="Domain"> <Configurations> <Configuration Name="Conf"> @@ -83,6 +96,11 @@ private: return config; } + + using GetParamFunc = bool (*)(); + std::string mSubsystemPath = std::string(PLUGIN_PATH) + (*PLUGIN_PATH ? "/":"") + PLUGIN_NAME; + std::unique_ptr<DynamicLibrary> mDynamicLibrary; + bool (*mGetParamFunc)(); }; SCENARIO_METHOD(BoolPF, "Auto sync") @@ -91,7 +109,7 @@ SCENARIO_METHOD(BoolPF, "Auto sync") REQUIRE_NOTHROW(start()); THEN ("Parameter value is false according to the settings") { - REQUIRE_FALSE(introspectionSubsystem::getParameterValue()); + REQUIRE_FALSE(getParameterValue()); AND_THEN ("Tuning is off") { REQUIRE_FALSE(isTuningModeOn()); @@ -103,7 +121,7 @@ SCENARIO_METHOD(BoolPF, "Auto sync") REQUIRE_NOTHROW(setParameterValue(true)); THEN ("Sync is done") { - CHECK(introspectionSubsystem::getParameterValue()); + CHECK(getParameterValue()); } } } @@ -114,13 +132,13 @@ SCENARIO_METHOD(BoolPF, "Auto sync") REQUIRE_NOTHROW(setParameterValue(true)); THEN ("Sync should not have occurred yet") { - REQUIRE_FALSE(introspectionSubsystem::getParameterValue()); + REQUIRE_FALSE(getParameterValue()); WHEN ("Turning autosync on") { REQUIRE_NOTHROW(setAutoSync(true)); THEN ("Sync is done") { - CHECK(introspectionSubsystem::getParameterValue()); + CHECK(getParameterValue()); } } } diff --git a/upstream/test/functional-tests/CMakeLists.txt b/upstream/test/functional-tests/CMakeLists.txt index c3d02d0..b938231 100644 --- a/upstream/test/functional-tests/CMakeLists.txt +++ b/upstream/test/functional-tests/CMakeLists.txt @@ -48,6 +48,8 @@ if(BUILD_TESTING) find_package(LibXml2 REQUIRED) + target_compile_definitions(parameterFunctionalTest PUBLIC -D PLUGIN_NAME=\"introspection-subsystem\" PLUGIN_PATH=\"\") + target_link_libraries(parameterFunctionalTest PRIVATE parameter PRIVATE pfw_utility catch tmpfile LibXml2::libxml2 introspection-subsystem) diff --git a/upstream/test/introspection-subsystem/include/IntrospectionEntryPoint.h b/upstream/test/introspection-subsystem/include/IntrospectionEntryPoint.h index b7feea9..84dc71b 100644 --- a/upstream/test/introspection-subsystem/include/IntrospectionEntryPoint.h +++ b/upstream/test/introspection-subsystem/include/IntrospectionEntryPoint.h @@ -36,6 +36,15 @@ namespace parameterFramework namespace introspectionSubsystem { +#ifdef __cplusplus +extern "C" { +#endif + INTROSPECTION_SUBSYSTEM_EXPORT bool getParameterValue(); + +#ifdef __cplusplus +} +#endif + } // namespace introspectionSubsystem } // namespace parameterFramework diff --git a/upstream/test/test-platform/TestPlatform.cpp b/upstream/test/test-platform/TestPlatform.cpp index 69715ea..d090939 100644 --- a/upstream/test/test-platform/TestPlatform.cpp +++ b/upstream/test/test-platform/TestPlatform.cpp @@ -38,8 +38,8 @@ using std::string; -CTestPlatform::CTestPlatform(const string &strClass, uint16_t iPortNumber) - : mParameterMgrPlatformConnector(strClass), mLogger(), mRemoteProcessorServer(iPortNumber) +CTestPlatform::CTestPlatform(const string &strClass, std::string bindAddress) + : mParameterMgrPlatformConnector(strClass), mLogger(), mRemoteProcessorServer(bindAddress) { mParameterMgrPlatformConnector.setLogger(&mLogger); } diff --git a/upstream/test/test-platform/TestPlatform.h b/upstream/test/test-platform/TestPlatform.h index f9c27f7..8917dbb 100644 --- a/upstream/test/test-platform/TestPlatform.h +++ b/upstream/test/test-platform/TestPlatform.h @@ -45,7 +45,7 @@ class CTestPlatform typedef CCommandHandler::CommandStatus CommandReturn; public: - CTestPlatform(const std::string &strclass, uint16_t iPortNumber); + CTestPlatform(const std::string &strclass, std::string bindAddress); virtual ~CTestPlatform(); // Init diff --git a/upstream/test/test-platform/main.cpp b/upstream/test/test-platform/main.cpp index 6cb5267..f09fcba 100644 --- a/upstream/test/test-platform/main.cpp +++ b/upstream/test/test-platform/main.cpp @@ -41,11 +41,11 @@ using std::cerr; using std::endl; using std::string; -static const uint16_t defaultPortNumber = 5001; +static const std::string defaultBindAddress("5001"); static void showUsage() { - cerr << "test-platform [-h|--help] <file path> [port number, default " << defaultPortNumber + cerr << "test-platform [-h|--help] <file path> [bind address, default " << defaultBindAddress << "]" << endl; } @@ -86,26 +86,22 @@ int main(int argc, char *argv[]) auto filePath = options.front(); options.pop_front(); - // Handle optional port number argument - uint16_t portNumber = defaultPortNumber; + // Handle optional bind address argument + auto bindAddress = defaultBindAddress; if (not options.empty()) { - if (not convertTo(options.front(), portNumber)) { - showInvalidUsage("Could not convert \"" + options.front() + - "\" to a socket port number."); - return 2; - }; + bindAddress = options.front(); options.pop_front(); } // All arguments should have been consumed if (not options.empty()) { showInvalidUsage("Unexpected extra arguments: " + utility::asString(options)); - return 3; + return 2; } string strError; - if (!CTestPlatform(filePath, portNumber).run(strError)) { + if (!CTestPlatform(filePath, bindAddress).run(strError)) { cerr << "Test-platform error:" << strError.c_str() << endl; return -1; diff --git a/upstream/test/tmpfile/CMakeLists.txt b/upstream/test/tmpfile/CMakeLists.txt index 0dba1a1..1975f3a 100644 --- a/upstream/test/tmpfile/CMakeLists.txt +++ b/upstream/test/tmpfile/CMakeLists.txt @@ -34,4 +34,9 @@ if(BUILD_TESTING) endif () add_library(tmpfile STATIC ${OS_SPECIFIC_TMPFILE}) + + if (NOT WIN32) + target_compile_definitions(tmpfile PUBLIC -D RW_PATH=\"\") + endif () + endif() diff --git a/upstream/test/tmpfile/posix/TmpFile.cpp b/upstream/test/tmpfile/posix/TmpFile.cpp index 5968cde..59fe441 100644 --- a/upstream/test/tmpfile/posix/TmpFile.cpp +++ b/upstream/test/tmpfile/posix/TmpFile.cpp @@ -42,7 +42,7 @@ std::string TmpFile::mktmp() { using std::string; - char path[] = "Tmp_ParameterFramework_XXXXXX"; + char path[] = RW_PATH "Tmp_ParameterFramework_XXXXXX"; int fd = mkstemp(path); if (fd == -1) { throwErrnoError("Could not create tmp file with pattern \"" + string(path) + '"'); diff --git a/upstream/xmlserializer/XmlElement.cpp b/upstream/xmlserializer/XmlElement.cpp index 9c3950d..e00d08e 100644 --- a/upstream/xmlserializer/XmlElement.cpp +++ b/upstream/xmlserializer/XmlElement.cpp @@ -262,7 +262,6 @@ bool CXmlElement::CChildIterator::next(CXmlElement &xmlChildElement) return false; } -template bool CXmlElement::getAttribute(const std::string &name, std::string &value) const; template bool CXmlElement::getAttribute(const std::string &name, bool &value) const; template bool CXmlElement::getAttribute(const std::string &name, signed char &value) const; template bool CXmlElement::getAttribute(const std::string &name, unsigned char &value) const; @@ -277,8 +276,6 @@ template bool CXmlElement::getAttribute(const std::string &name, unsigned long l template bool CXmlElement::getAttribute(const std::string &name, float &value) const; template bool CXmlElement::getAttribute(const std::string &name, double &value) const; -template void CXmlElement::setAttribute(const std::string &name, const std::string &value); -template void CXmlElement::setAttribute(const std::string &name, const bool &value); template void CXmlElement::setAttribute(const std::string &name, const signed char &value); template void CXmlElement::setAttribute(const std::string &name, const unsigned char &value); template void CXmlElement::setAttribute(const std::string &name, const short &value); |