diff --git a/src/net/connection_client.hpp b/src/net/connection_client.hpp index 5cf6946cb25c97ff6ee87dc91b40a64a83a2ee16..70ada47277c210f31e316eedeb5e33159dcd7572 100644 --- a/src/net/connection_client.hpp +++ b/src/net/connection_client.hpp @@ -15,7 +15,7 @@ namespace rmrf::net { class connection_client : public std::enable_shared_from_this<connection_client> { public: - typedef std::function<void(std::string)> incomming_data_cb; + typedef std::function<void(std::shared_ptr<std::string>)> incomming_data_cb; protected: incomming_data_cb in_data_cb; public: diff --git a/src/net/tcp_client.cpp b/src/net/tcp_client.cpp index 11a704b66d73c1cd2113d507afe49a5998d77a61..aaf02cf8f6d2bf47d71cd33c3eaeb76593e20218 100644 --- a/src/net/tcp_client.cpp +++ b/src/net/tcp_client.cpp @@ -56,11 +56,11 @@ void tcp_client::write_data(std::string data) { this->write_queue.push_back(std::make_shared<impl::NICBuffer>(data.c_str(), data.size())); } -std::string buffer_to_string(char* buffer, ssize_t bufflen) +inline std::shared_ptr<std::string> buffer_to_string(char* buffer, ssize_t bufflen) { // For some wired reaseon the compiler refuses to find the correct constructor of string // without this extra method. - std::string ret(buffer, (int) bufflen); + std::shared_ptr<std::string> ret = std::make_shared<std::string>(buffer, (int) bufflen); return ret; } diff --git a/src/net/tcp_client.hpp b/src/net/tcp_client.hpp index e0b7889ebc2f1e9f1c0f1f99f54161aa1645b95f..a6c73d86f8405f289017907df658c5e39d01d05e 100644 --- a/src/net/tcp_client.hpp +++ b/src/net/tcp_client.hpp @@ -53,6 +53,7 @@ private: std::list<std::shared_ptr<impl::NICBuffer>> write_queue; public: tcp_client(const destructor_cb_type destructor_cb_, auto_fd&& socket_fd, std::string peer_address_, uint16_t port_); + tcp_client(const std::string); virtual ~tcp_client(); virtual void write_data(std::string data); std::string get_peer_address();