qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject svn commit: r1487960 - in /qpid/trunk/qpid/cpp/src/qpid/broker/amqp: Relay.cpp Relay.h
Date Thu, 30 May 2013 18:41:21 GMT
Author: gsim
Date: Thu May 30 18:41:21 2013
New Revision: 1487960

URL: http://svn.apache.org/r1487960
Log:
QPID-4893: prevent uninitialised buffered messages being transfered

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.h

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.cpp?rev=1487960&r1=1487959&r2=1487960&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.cpp Thu May 30 18:41:21 2013
@@ -28,7 +28,7 @@ namespace qpid {
 namespace broker {
 namespace amqp {
 
-Relay::Relay(size_t max_) : credit(0), max(max_), current(0), isDetached(false), out(0),
in(0) {}
+Relay::Relay(size_t max_) : credit(0), max(max_), head(0), tail(0), isDetached(false), out(0),
in(0) {}
 void Relay::check()
 {
     if (isDetached) throw qpid::Exception("other end of relay has been detached");
@@ -38,8 +38,8 @@ bool Relay::send(pn_link_t* link)
     BufferedTransfer* c(0);
     {
         qpid::sys::ScopedLock<qpid::sys::Mutex> l(lock);
-        if (current < buffer.size()) {
-            c = &buffer[current++];
+        if (head < tail) {
+            c = &buffer[head++];
         } else {
             return false;
         }
@@ -59,6 +59,10 @@ void Relay::received(pn_link_t* link, pn
 {
     BufferedTransfer& received = push();
     received.initIn(link, delivery);
+    {
+        qpid::sys::ScopedLock<qpid::sys::Mutex> l(lock);
+        ++tail;
+    }
     if (out) out->wakeup();
 }
 size_t Relay::size() const
@@ -66,7 +70,7 @@ size_t Relay::size() const
     qpid::sys::ScopedLock<qpid::sys::Mutex> l(lock);
     return buffer.size();
 }
-BufferedTransfer& Relay::head()
+BufferedTransfer& Relay::front()
 {
     qpid::sys::ScopedLock<qpid::sys::Mutex> l(lock);
     return buffer.front();
@@ -75,7 +79,8 @@ void Relay::pop()
 {
     qpid::sys::ScopedLock<qpid::sys::Mutex> l(lock);
     buffer.pop_front();
-    if (current) --current;
+    if (head) --head;
+    if (tail) --tail;
 }
 void Relay::setCredit(int c)
 {
@@ -100,12 +105,14 @@ void Relay::detached(Outgoing*)
 {
     out = 0;
     isDetached = true;
+    std::cerr << "Outgoing link detached from relay" << std::endl;
     if (in) in->wakeup();
 }
 void Relay::detached(Incoming*)
 {
     in = 0;
     isDetached = true;
+    std::cerr << "Incoming link detached from relay" << std::endl;
     if (out) out->wakeup();
 }
 
@@ -182,7 +189,7 @@ IncomingToRelay::IncomingToRelay(pn_link
 bool IncomingToRelay::settle()
 {
     bool result(false);
-    while (relay->size() && relay->head().settle()) {
+    while (relay->size() && relay->front().settle()) {
         result = true;
         relay->pop();
     }

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.h?rev=1487960&r1=1487959&r2=1487960&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/amqp/Relay.h Thu May 30 18:41:21 2013
@@ -68,7 +68,7 @@ class Relay
     Relay(size_t max);
     void check();
     size_t size() const;
-    BufferedTransfer& head();
+    BufferedTransfer& front();
     void pop();
     bool send(pn_link_t*);
     void received(pn_link_t* link, pn_delivery_t* delivery);
@@ -82,7 +82,8 @@ class Relay
     std::deque<BufferedTransfer> buffer;//TODO: optimise by replacing with simple circular
array
     int credit;//issued by outgoing peer, decremented everytime we send a message on outgoing
link
     size_t max;
-    size_t current;
+    size_t head;
+    size_t tail;
     bool isDetached;
     Outgoing* out;
     Incoming* in;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message