summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/Link.cpp
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2012-10-25 14:13:51 +0000
committerCharles E. Rolke <chug@apache.org>2012-10-25 14:13:51 +0000
commit22b741746766e7b39f101e720bacd51f9b400ec6 (patch)
treee2acf1b1196bca5109af09e31af91ba9bee9cd0f /cpp/src/qpid/broker/Link.cpp
parent717be8a935a55004e73797476ead2c3b3c00d8d8 (diff)
downloadqpid-python-22b741746766e7b39f101e720bacd51f9b400ec6.tar.gz
QPID-4392 C++ Broker link channel number wrap.
Maintain a pool of available channel numbers. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1402158 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/Link.cpp')
-rw-r--r--cpp/src/qpid/broker/Link.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/cpp/src/qpid/broker/Link.cpp b/cpp/src/qpid/broker/Link.cpp
index b014217180..82389a5e3d 100644
--- a/cpp/src/qpid/broker/Link.cpp
+++ b/cpp/src/qpid/broker/Link.cpp
@@ -30,6 +30,7 @@
#include "qpid/log/Statement.h"
#include "qpid/framing/enum.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qpid/framing/amqp_types.h"
#include "qpid/broker/AclModule.h"
#include "qpid/broker/Exchange.h"
#include "qpid/UrlArray.h"
@@ -148,7 +149,7 @@ Link::Link(const string& _name,
currentInterval(1),
closing(false),
reconnectNext(0), // Index of next address for reconnecting in url.
- channelCounter(1),
+ freeChannels(1, framing::CHANNEL_MAX),
connection(0),
agent(0),
listener(l),
@@ -542,12 +543,26 @@ bool Link::hideManagement() const {
return !mgmtObject || ( broker && broker->isInCluster());
}
-uint Link::nextChannel()
+// Allocate channel from link free pool
+framing::ChannelId Link::nextChannel()
{
Mutex::ScopedLock mutex(lock);
- if (channelCounter >= framing::CHANNEL_MAX)
- channelCounter = 1;
- return channelCounter++;
+ if (!freeChannels.empty()) {
+ framing::ChannelId c = freeChannels.front();
+ freeChannels -= c;
+ QPID_LOG(debug, "Link " << name << " allocates channel: " << c);
+ return c;
+ } else {
+ throw Exception(Msg() << "Link " << name << " channel pool is empty");
+ }
+}
+
+// Return channel to link free pool
+void Link::returnChannel(framing::ChannelId c)
+{
+ Mutex::ScopedLock mutex(lock);
+ QPID_LOG(debug, "Link " << name << " frees channel: " << c);
+ freeChannels += c;
}
void Link::notifyConnectionForced(const string text)