[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 02/03: zmq: fix for data corruption when no
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 02/03: zmq: fix for data corruption when not using tags |
Date: |
Mon, 9 Feb 2015 17:49:00 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 2d4940d88884f023f474c7d496ff22114e5f3ff3
Author: Tim O'Shea <address@hidden>
Date: Sun Feb 8 17:22:23 2015 -0500
zmq: fix for data corruption when not using tags
---
gr-zeromq/lib/pub_sink_impl.cc | 14 ++++++++++----
gr-zeromq/lib/push_sink_impl.cc | 13 +++++++++----
gr-zeromq/lib/rep_sink_impl.cc | 13 ++++++++++---
3 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/gr-zeromq/lib/pub_sink_impl.cc b/gr-zeromq/lib/pub_sink_impl.cc
index 5afcb72..c103069 100644
--- a/gr-zeromq/lib/pub_sink_impl.cc
+++ b/gr-zeromq/lib/pub_sink_impl.cc
@@ -80,11 +80,17 @@ namespace gr {
}
// create message copy and send
- zmq::message_t msg(header.length() + d_itemsize*d_vlen*noutput_items);
- //std::cout << "PUB: Header Len: " << header.length() << ", Data Length:
" << d_itemsize*d_vlen*noutput_items << "\n";
- if(d_pass_tags)
+ int payloadlen = d_itemsize * d_vlen * noutput_items;
+ int msglen = d_pass_tags ? payloadlen + header.length() : payloadlen;
+ zmq::message_t msg(msglen);
+
+ if(d_pass_tags){
memcpy((void*) msg.data(), header.c_str(), header.length() );
- memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*noutput_items);
+ memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*noutput_items);
+ } else {
+ memcpy((uint8_t *)msg.data(), in, d_itemsize*d_vlen*noutput_items);
+ }
+
d_socket->send(msg);
return noutput_items;
diff --git a/gr-zeromq/lib/push_sink_impl.cc b/gr-zeromq/lib/push_sink_impl.cc
index 677de10..7c06dc5 100644
--- a/gr-zeromq/lib/push_sink_impl.cc
+++ b/gr-zeromq/lib/push_sink_impl.cc
@@ -90,11 +90,16 @@ namespace gr {
}
// create message copy and send
- zmq::message_t msg(header.length() + d_itemsize*d_vlen*noutput_items);
+ int payloadlen = d_itemsize * d_vlen * noutput_items;
+ int msglen = d_pass_tags ? payloadlen + header.length() : payloadlen;
+ zmq::message_t msg(msglen);
- if(d_pass_tags)
- memcpy((void*) msg.data(), header.c_str(), header.length());
- memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*noutput_items);
+ if(d_pass_tags){
+ memcpy((void*) msg.data(), header.c_str(), header.length() );
+ memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*noutput_items);
+ } else {
+ memcpy((uint8_t *)msg.data(), in, d_itemsize*d_vlen*noutput_items);
+ }
d_socket->send(msg);
return noutput_items;
diff --git a/gr-zeromq/lib/rep_sink_impl.cc b/gr-zeromq/lib/rep_sink_impl.cc
index 85f9a78..034a5b0 100644
--- a/gr-zeromq/lib/rep_sink_impl.cc
+++ b/gr-zeromq/lib/rep_sink_impl.cc
@@ -93,11 +93,18 @@ namespace gr {
header = gen_tag_header( offset, tags );
}
+
// create message copy and send
- zmq::message_t msg(header.length() + d_itemsize*d_vlen*nitems_send);
- if(d_pass_tags)
+ int payloadlen = d_itemsize * d_vlen * noutput_items;
+ int msglen = d_pass_tags ? payloadlen + header.length() : payloadlen;
+ zmq::message_t msg(msglen);
+
+ if(d_pass_tags){
memcpy((void*) msg.data(), header.c_str(), header.length() );
- memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*nitems_send);
+ memcpy((uint8_t *)msg.data() + header.length(), in,
d_itemsize*d_vlen*noutput_items);
+ } else {
+ memcpy((uint8_t *)msg.data(), in, d_itemsize*d_vlen*noutput_items);
+ }
d_socket->send(msg);
return nitems_send;