diff options
author | Thomas Habets <thomas@habets.se> | 2020-08-11 12:09:21 +0100 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2020-08-14 04:19:58 -0700 |
commit | 8df39c1ac66b8fe38f804e14459b831491ad6270 (patch) | |
tree | 117cfec2b32dfb58e23b3f74bd6a6e6e8977a439 | |
parent | 4b8725982361f66304e53391c1411de1d5840bff (diff) |
blocks/tcp_connection: Remove manual memory management
-rw-r--r-- | gr-blocks/lib/tcp_connection.cc | 12 | ||||
-rw-r--r-- | gr-blocks/lib/tcp_connection.h | 8 |
2 files changed, 6 insertions, 14 deletions
diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc index 4634039ae4..e262ca01ac 100644 --- a/gr-blocks/lib/tcp_connection.cc +++ b/gr-blocks/lib/tcp_connection.cc @@ -45,10 +45,10 @@ void tcp_connection::send(pmt::pmt_t vector) size_t len = pmt::blob_length(vector); // Asio async_write() requires the buffer to remain valid until the handler is called. - std::shared_ptr<char[]> txbuf(new char[len]); + auto txbuf = std::make_shared<std::vector<char>>(len); size_t temp = 0; - memcpy(txbuf.get(), pmt::uniform_vector_elements(vector, temp), len); + memcpy(txbuf->data(), pmt::uniform_vector_elements(vector, temp), len); size_t offset = 0; while (offset < len) { @@ -58,12 +58,8 @@ void tcp_connection::send(pmt::pmt_t vector) size_t send_len = std::min((len - offset), d_buf.size()); boost::asio::async_write( d_socket, - boost::asio::buffer(txbuf.get() + offset, send_len), - boost::bind(&tcp_connection::handle_write, - this, - txbuf, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); + boost::asio::buffer(txbuf->data() + offset, send_len), + [txbuf](const boost::system::error_code& error, size_t bytes_transferred) {}); offset += send_len; } } diff --git a/gr-blocks/lib/tcp_connection.h b/gr-blocks/lib/tcp_connection.h index 2dd914ab71..f97f8a605b 100644 --- a/gr-blocks/lib/tcp_connection.h +++ b/gr-blocks/lib/tcp_connection.h @@ -34,6 +34,8 @@ private: int MTU = 10000, bool no_delay = false); + void handle_read(const boost::system::error_code& error, size_t bytes_transferred); + public: typedef std::shared_ptr<tcp_connection> sptr; @@ -44,12 +46,6 @@ public: void start(gr::basic_block* block); void send(pmt::pmt_t vector); - void handle_read(const boost::system::error_code& error, size_t bytes_transferred); - void handle_write(std::shared_ptr<char[]> txbuf, - const boost::system::error_code& error, - size_t bytes_transferred) - { - } }; } /* namespace blocks */ |