diff options
Diffstat (limited to 'gr-zeromq/lib/pull_msg_source_impl.cc')
-rw-r--r-- | gr-zeromq/lib/pull_msg_source_impl.cc | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/gr-zeromq/lib/pull_msg_source_impl.cc b/gr-zeromq/lib/pull_msg_source_impl.cc index 9a467e597f..56dba69735 100644 --- a/gr-zeromq/lib/pull_msg_source_impl.cc +++ b/gr-zeromq/lib/pull_msg_source_impl.cc @@ -16,6 +16,7 @@ #include "tag_headers.h" #include <gnuradio/io_signature.h> #include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/make_unique.hpp> #include <boost/thread/thread.hpp> namespace gr { @@ -31,6 +32,8 @@ pull_msg_source_impl::pull_msg_source_impl(char* address, int timeout, bool bind gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)), d_timeout(timeout), + d_context(1), + d_socket(d_context, ZMQ_PULL), d_port(pmt::mp("out")) { int major, minor, patch; @@ -40,32 +43,25 @@ pull_msg_source_impl::pull_msg_source_impl(char* address, int timeout, bool bind d_timeout = timeout * 1000; } - d_context = new zmq::context_t(1); - d_socket = new zmq::socket_t(*d_context, ZMQ_PULL); - int time = 0; - d_socket->setsockopt(ZMQ_LINGER, &time, sizeof(time)); + d_socket.setsockopt(ZMQ_LINGER, &time, sizeof(time)); if (bind) { - d_socket->bind(address); + d_socket.bind(address); } else { - d_socket->connect(address); + d_socket.connect(address); } message_port_register_out(d_port); } -pull_msg_source_impl::~pull_msg_source_impl() -{ - d_socket->close(); - delete d_socket; - delete d_context; -} +pull_msg_source_impl::~pull_msg_source_impl() {} bool pull_msg_source_impl::start() { d_finished = false; - d_thread = new boost::thread(boost::bind(&pull_msg_source_impl::readloop, this)); + d_thread = boost::make_unique<boost::thread>( + boost::bind(&pull_msg_source_impl::readloop, this)); return true; } @@ -80,7 +76,7 @@ void pull_msg_source_impl::readloop() { while (!d_finished) { - zmq::pollitem_t items[] = { { static_cast<void*>(*d_socket), 0, ZMQ_POLLIN, 0 } }; + zmq::pollitem_t items[] = { { static_cast<void*>(d_socket), 0, ZMQ_POLLIN, 0 } }; zmq::poll(&items[0], 1, d_timeout); // If we got a reply, process @@ -89,9 +85,9 @@ void pull_msg_source_impl::readloop() // Receive data zmq::message_t msg; #if USE_NEW_CPPZMQ_SEND_RECV - d_socket->recv(msg); + d_socket.recv(msg); #else - d_socket->recv(&msg); + d_socket.recv(&msg); #endif std::string buf(static_cast<char*>(msg.data()), msg.size()); |