Skip to content

Commit

Permalink
Merge pull request #299 from redboltz/fix_298
Browse files Browse the repository at this point in the history
Fix 298
  • Loading branch information
redboltz authored Jun 25, 2019
2 parents 5802d04 + a6058ca commit b441187
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 90 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MQTT client/server for C++14 based on Boost.Asio

Version 4.0.0 [![Build Status](https://travis-ci.org/redboltz/mqtt_cpp.svg?branch=master)](https://travis-ci.org/redboltz/mqtt_cpp)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.abp_mqtt_cpp_test?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=5&branchName=master) [![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp)
Version 5.0.0 [![Build Status](https://travis-ci.org/redboltz/mqtt_cpp.svg?branch=master)](https://travis-ci.org/redboltz/mqtt_cpp)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.abp_mqtt_cpp_test?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=5&branchName=master) [![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp)

[MQTT v5 is supported](https://github.com/redboltz/mqtt_cpp/wiki/MQTT-v5) since version 4.0.0.

Expand Down
12 changes: 6 additions & 6 deletions include/mqtt/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class client : public endpoint<Socket, std::mutex, std::lock_guard, PacketIdByte
* You can configure the socket prior to connect.
* @param func finish handler that is called when the session is finished
*/
void connect(std::unique_ptr<Socket>&& socket, async_handler_t func = async_handler_t()) {
void connect(std::shared_ptr<Socket>&& socket, async_handler_t func = async_handler_t()) {
connect(std::move(socket), std::vector<v5::property_variant>{}, std::move(func));
}

Expand All @@ -495,7 +495,7 @@ class client : public endpoint<Socket, std::mutex, std::lock_guard, PacketIdByte
* 3.1.2.11 CONNECT Properties
* @param func finish handler that is called when the session is finished
*/
void connect(std::unique_ptr<Socket>&& socket, std::vector<v5::property_variant> props, async_handler_t func = async_handler_t()) {
void connect(std::shared_ptr<Socket>&& socket, std::vector<v5::property_variant> props, async_handler_t func = async_handler_t()) {
as::ip::tcp::resolver r(ios_);
#if BOOST_VERSION < 106600
as::ip::tcp::resolver::query q(host_, port_);
Expand Down Expand Up @@ -763,26 +763,26 @@ class client : public endpoint<Socket, std::mutex, std::lock_guard, PacketIdByte

private:
template <typename Strand>
void setup_socket(std::unique_ptr<tcp_endpoint<as::ip::tcp::socket, Strand>>& socket) {
void setup_socket(std::shared_ptr<tcp_endpoint<as::ip::tcp::socket, Strand>>& socket) {
socket.reset(new Socket(ios_));
}

#if defined(MQTT_USE_WS)
template <typename Strand>
void setup_socket(std::unique_ptr<ws_endpoint<as::ip::tcp::socket, Strand>>& socket) {
void setup_socket(std::shared_ptr<ws_endpoint<as::ip::tcp::socket, Strand>>& socket) {
socket.reset(new Socket(ios_));
}
#endif // defined(MQTT_USE_WS)

#if !defined(MQTT_NO_TLS)
template <typename Strand>
void setup_socket(std::unique_ptr<tcp_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>>& socket) {
void setup_socket(std::shared_ptr<tcp_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>>& socket) {
socket.reset(new Socket(ios_, ctx_));
}

#if defined(MQTT_USE_WS)
template <typename Strand>
void setup_socket(std::unique_ptr<ws_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>>& socket) {
void setup_socket(std::shared_ptr<ws_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>>& socket) {
socket.reset(new Socket(ios_, ctx_));
}
#endif // defined(MQTT_USE_WS)
Expand Down
12 changes: 6 additions & 6 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
* @brief Constructor for server.
* socket should have already been connected with another endpoint.
*/
explicit endpoint(std::unique_ptr<Socket> socket, protocol_version version = protocol_version::undetermined)
explicit endpoint(std::shared_ptr<Socket> socket, protocol_version version = protocol_version::undetermined)
:socket_(std::move(socket))
,connected_(true)
,h_mqtt_message_processed_(
Expand Down Expand Up @@ -7285,18 +7285,18 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
}

/**
* @brief Get Socket unique_ptr reference.
* @brief Get Socket shared_ptr reference.
* @return refereence of Socket unique_ptr
*/
std::unique_ptr<Socket>& socket() {
std::shared_ptr<Socket>& socket() {
return socket_;
}

/**
* @brief Get Socket unique_ptr const reference.
* @brief Get Socket shared_ptr const reference.
* @return const refereence of Socket unique_ptr
*/
std::unique_ptr<Socket> const& socket() const {
std::shared_ptr<Socket> const& socket() const {
return socket_;
}

Expand Down Expand Up @@ -10816,7 +10816,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
bool clean_session_{false};

private:
std::unique_ptr<Socket> socket_;
std::shared_ptr<Socket> socket_;
std::atomic<bool> connected_{false};
std::atomic<bool> mqtt_connected_{false};

Expand Down
Loading

0 comments on commit b441187

Please sign in to comment.