diff options
Diffstat (limited to 'qpid/cpp/src/qpid/broker/Link.cpp')
| -rw-r--r-- | qpid/cpp/src/qpid/broker/Link.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/qpid/cpp/src/qpid/broker/Link.cpp b/qpid/cpp/src/qpid/broker/Link.cpp index b014217180..82389a5e3d 100644 --- a/qpid/cpp/src/qpid/broker/Link.cpp +++ b/qpid/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) |
