From 405de3ecd5624a350668406f5476905e5e8a1286 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 30 May 2015 17:36:06 +0200 Subject: Use shared_ptr in ZMQ input instead of pointers --- src/InputReader.h | 6 ++++-- src/InputZeroMQReader.cpp | 16 ++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/InputReader.h b/src/InputReader.h index 13d49b8..6156c94 100644 --- a/src/InputReader.h +++ b/src/InputReader.h @@ -31,6 +31,8 @@ #endif #include +#include +#include #if defined(HAVE_ZEROMQ) # include "zmq.hpp" # include "ThreadsafeQueue.h" @@ -143,7 +145,7 @@ struct zmq_input_overflow : public std::exception struct InputZeroMQThreadData { - ThreadsafeQueue *in_messages; + ThreadsafeQueue > > *in_messages; std::string uri; unsigned max_queued_frames; @@ -203,7 +205,7 @@ class InputZeroMQReader : public InputReader std::string uri_; InputZeroMQWorker worker_; - ThreadsafeQueue in_messages_; + ThreadsafeQueue > > in_messages_; struct InputZeroMQThreadData workerdata_; }; diff --git a/src/InputZeroMQReader.cpp b/src/InputZeroMQReader.cpp index 683968f..eb50669 100644 --- a/src/InputZeroMQReader.cpp +++ b/src/InputZeroMQReader.cpp @@ -37,6 +37,7 @@ #include #include "zmq.hpp" #include +#include #include "porting.h" #include "InputReader.h" #include "PcDebug.h" @@ -84,16 +85,14 @@ int InputZeroMQReader::GetNextFrame(void* buffer) { const size_t framesize = 6144; - uint8_t* incoming; + boost::shared_ptr > incoming; in_messages_.wait_and_pop(incoming); if (! workerdata_.running) { throw zmq_input_overflow(); } - memcpy(buffer, incoming, framesize); - - delete[] incoming; + memcpy(buffer, &incoming->front(), framesize); return framesize; } @@ -160,18 +159,15 @@ void InputZeroMQWorker::RecvProcess(struct InputZeroMQThreadData* workerdata) // TODO error handling } else { - uint8_t* buf = new uint8_t[6144]; + boost::shared_ptr > buf = + boost::make_shared >(6144, 0x55); const int framesize = dab_msg->buflen[i]; - memcpy(buf, + memcpy(&buf->front(), ((uint8_t*)incoming.data()) + offset, framesize); - // pad to 6144 bytes - memset(&((uint8_t*)buf)[framesize], - 0x55, 6144 - framesize); - offset += framesize; queue_size = workerdata->in_messages->push(buf); -- cgit v1.2.3