summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2013-09-10 11:03:20 +0000
committerGordon Sim <gsim@apache.org>2013-09-10 11:03:20 +0000
commite286fe2d1cd165c34ea7159c4b744842aa61f930 (patch)
tree1d33c704a1b1a6af641a73b5fcb8d959e57b04a6
parent396fbcffc859e00528927f0cb37709eb2147e434 (diff)
downloadqpid-python-e286fe2d1cd165c34ea7159c4b744842aa61f930.tar.gz
QPID-5122: cleaner encoding of index for delivery tags
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1521433 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/broker/amqp/Outgoing.cpp18
-rw-r--r--qpid/cpp/src/qpid/broker/amqp/Outgoing.h3
2 files changed, 17 insertions, 4 deletions
diff --git a/qpid/cpp/src/qpid/broker/amqp/Outgoing.cpp b/qpid/cpp/src/qpid/broker/amqp/Outgoing.cpp
index 3d2644380a..8b2b380173 100644
--- a/qpid/cpp/src/qpid/broker/amqp/Outgoing.cpp
+++ b/qpid/cpp/src/qpid/broker/amqp/Outgoing.cpp
@@ -29,6 +29,7 @@
#include "qpid/sys/OutputControl.h"
#include "qpid/amqp/descriptors.h"
#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/framing/Buffer.h"
#include "qpid/framing/reply_exceptions.h"
#include "qpid/log/Statement.h"
@@ -93,8 +94,7 @@ void OutgoingFromQueue::write(const char* data, size_t size)
void OutgoingFromQueue::handle(pn_delivery_t* delivery)
{
- pn_delivery_tag_t tag = pn_delivery_tag(delivery);
- size_t i = *reinterpret_cast<const size_t*>(tag.bytes);
+ size_t i = Record::getIndex(pn_delivery_tag(delivery));
Record& r = deliveries[i];
if (pn_delivery_writable(delivery)) {
assert(r.msg);
@@ -260,8 +260,10 @@ OutgoingFromQueue::Record::Record() : delivery(0), disposition(0), index(0) {}
void OutgoingFromQueue::Record::init(size_t i)
{
index = i;
- tag.bytes = reinterpret_cast<const char*>(&index);
- tag.size = sizeof(index);
+ qpid::framing::Buffer buffer(tagData, Record::TAG_WIDTH);
+ buffer.putUInt<Record::TAG_WIDTH>(index);
+ tag.bytes = tagData;
+ tag.size = Record::TAG_WIDTH;
}
void OutgoingFromQueue::Record::reset()
{
@@ -271,5 +273,13 @@ void OutgoingFromQueue::Record::reset()
disposition = 0;
}
+size_t OutgoingFromQueue::Record::getIndex(pn_delivery_tag_t t)
+{
+ assert(t.size == TAG_WIDTH);
+ qpid::framing::Buffer buffer(const_cast<char*>(t.bytes)/*won't ever be written to*/, t.size);
+ return (size_t) buffer.getUInt<TAG_WIDTH>();
+}
+
+
}}} // namespace qpid::broker::amqp
diff --git a/qpid/cpp/src/qpid/broker/amqp/Outgoing.h b/qpid/cpp/src/qpid/broker/amqp/Outgoing.h
index d333c54672..38d9e17190 100644
--- a/qpid/cpp/src/qpid/broker/amqp/Outgoing.h
+++ b/qpid/cpp/src/qpid/broker/amqp/Outgoing.h
@@ -118,10 +118,13 @@ class OutgoingFromQueue : public Outgoing, public qpid::broker::Consumer, public
int disposition;
size_t index;
pn_delivery_tag_t tag;
+ static const size_t TAG_WIDTH = sizeof(size_t);
+ char tagData[TAG_WIDTH];//index in encoded form, used for tag
Record();
void init(size_t i);
void reset();
+ static size_t getIndex(pn_delivery_tag_t);
};
const bool exclusive;