From 9463c0549ee94dca0b24e995c3c82263920b6120 Mon Sep 17 00:00:00 2001 From: Doralitze <doralitze@chaotikum.org> Date: Mon, 4 Jan 2021 20:39:31 +0100 Subject: [PATCH] chg: connection_client incomminb data cb to ptr of string --- src/net/connection_client.hpp | 2 +- src/net/tcp_client.cpp | 4 ++-- src/net/tcp_client.hpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/net/connection_client.hpp b/src/net/connection_client.hpp index 5cf6946..70ada47 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 11a704b..aaf02cf 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 e0b7889..a6c73d8 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(); -- GitLab