diff options
author | Nathan West <nathan.west@okstate.edu> | 2015-10-05 18:15:20 -0400 |
---|---|---|
committer | Nathan West <nathan.west@okstate.edu> | 2015-10-07 20:42:14 -0400 |
commit | bde02e814e7f68e6ebf945d7f294014605fd3239 (patch) | |
tree | 3d1dd558d67f307bef80c08fb784ed4610666b55 /gr-blocks/lib | |
parent | 7d9f13824e9986650a2f46806d6d6714b99780ce (diff) |
blocks: fix destruction and shutdown for socket_pdu
This removes the inheritance from stream_pdu_base and stop the
io_service and internal service thread when stop() and dtor are
called.
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/socket_pdu_impl.cc | 17 | ||||
-rw-r--r-- | gr-blocks/lib/socket_pdu_impl.h | 7 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 756e2dfd0f..7f7abd50be 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -128,6 +128,23 @@ namespace gr { d_started = true; } + socket_pdu_impl::~socket_pdu_impl() + { + stop(); + } + + bool + socket_pdu_impl::stop() + { + if (d_started) { + d_io_service.stop(); + d_thread.interrupt(); + d_thread.join(); + } + d_started = false; + return true; + } + void socket_pdu_impl::handle_tcp_read(const boost::system::error_code& error, size_t bytes_transferred) { diff --git a/gr-blocks/lib/socket_pdu_impl.h b/gr-blocks/lib/socket_pdu_impl.h index c0262ce59a..e45f6d4463 100644 --- a/gr-blocks/lib/socket_pdu_impl.h +++ b/gr-blocks/lib/socket_pdu_impl.h @@ -30,12 +30,15 @@ namespace gr { namespace blocks { - class socket_pdu_impl : public socket_pdu, public stream_pdu_base + class socket_pdu_impl : public socket_pdu { private: boost::asio::io_service d_io_service; std::vector<char> d_rxbuf; void run_io_service() { d_io_service.run(); } + gr::thread::thread d_thread; + bool d_started; + bool d_finished; // TCP specific boost::asio::ip::tcp::endpoint d_tcp_endpoint; @@ -62,6 +65,8 @@ namespace gr { public: socket_pdu_impl(std::string type, std::string addr, std::string port, int MTU = 10000, bool tcp_no_delay = false); + ~socket_pdu_impl(); + bool stop(); }; } /* namespace blocks */ |