summaryrefslogtreecommitdiffstats
path: root/src/InputZeroMQReader.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-05-30 17:36:06 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-05-30 17:36:06 +0200
commit405de3ecd5624a350668406f5476905e5e8a1286 (patch)
tree7ce7395d185f34b7777add78d584497b6fc4c852 /src/InputZeroMQReader.cpp
parent1f1d23622054ce204d9cf1c1a589c718321c667a (diff)
downloaddabmod-405de3ecd5624a350668406f5476905e5e8a1286.tar.gz
dabmod-405de3ecd5624a350668406f5476905e5e8a1286.tar.bz2
dabmod-405de3ecd5624a350668406f5476905e5e8a1286.zip
Use shared_ptr in ZMQ input instead of pointers
Diffstat (limited to 'src/InputZeroMQReader.cpp')
-rw-r--r--src/InputZeroMQReader.cpp16
1 files changed, 6 insertions, 10 deletions
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 <stdint.h>
#include "zmq.hpp"
#include <boost/thread/thread.hpp>
+#include <boost/make_shared.hpp>
#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<std::vector<uint8_t> > 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<std::vector<uint8_t> > buf =
+ boost::make_shared<std::vector<uint8_t> >(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);