From 79226ccb35dc1bc75130b9772b3502deba02a573 Mon Sep 17 00:00:00 2001 From: "Marcelo E. Magallon" Date: Wed, 11 Feb 2015 15:10:08 -0600 Subject: [PATCH 1/2] Change channel id type to quint16 My reading of the spec is that channel numbers are unsigned. --- src/qamqpchannel.cpp | 2 +- src/qamqpchannel_p.h | 4 ++-- src/qamqpframe.cpp | 4 ++-- src/qamqpframe_p.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qamqpchannel.cpp b/src/qamqpchannel.cpp index a33dbd0..9b3faa7 100644 --- a/src/qamqpchannel.cpp +++ b/src/qamqpchannel.cpp @@ -6,7 +6,7 @@ #include "qamqpclient.h" #include "qamqpclient_p.h" -int QAmqpChannelPrivate::nextChannelNumber = 0; +quint16 QAmqpChannelPrivate::nextChannelNumber = 0; QAmqpChannelPrivate::QAmqpChannelPrivate(QAmqpChannel *q) : channelNumber(0), opened(false), diff --git a/src/qamqpchannel_p.h b/src/qamqpchannel_p.h index 372f386..7551950 100644 --- a/src/qamqpchannel_p.h +++ b/src/qamqpchannel_p.h @@ -60,8 +60,8 @@ public: QPointer client; QString name; - int channelNumber; - static int nextChannelNumber; + quint16 channelNumber; + static quint16 nextChannelNumber; bool opened; bool needOpen; diff --git a/src/qamqpframe.cpp b/src/qamqpframe.cpp index 9c69805..a46d554 100644 --- a/src/qamqpframe.cpp +++ b/src/qamqpframe.cpp @@ -22,12 +22,12 @@ QAmqpFrame::~QAmqpFrame() { } -void QAmqpFrame::setChannel(qint16 channel) +void QAmqpFrame::setChannel(quint16 channel) { channel_ = channel; } -qint16 QAmqpFrame::channel() const +quint16 QAmqpFrame::channel() const { return channel_; } diff --git a/src/qamqpframe_p.h b/src/qamqpframe_p.h index a07e499..e81ef1b 100644 --- a/src/qamqpframe_p.h +++ b/src/qamqpframe_p.h @@ -39,8 +39,8 @@ public: FrameType type() const; - qint16 channel() const; - void setChannel(qint16 channel); + quint16 channel() const; + void setChannel(quint16 channel); virtual qint32 size() const; @@ -56,7 +56,7 @@ protected: private: qint8 type_; - qint16 channel_; + quint16 channel_; friend QDataStream &operator<<(QDataStream &stream, const QAmqpFrame &frame); friend QDataStream &operator>>(QDataStream &stream, QAmqpFrame &frame); From 2652206d18a9e6f5e6c72f14c60c8c03c0a70920 Mon Sep 17 00:00:00 2001 From: "Marcelo E. Magallon" Date: Wed, 11 Feb 2015 15:11:33 -0600 Subject: [PATCH 2/2] Increment nextChannelNumber only once nextChannelNumber is being incremented twice. When the counter wraps around it starts declaring already existing channels and the AMQP server disconnects the client. This patch doubles the number of channels that can be created before this happens. --- src/qamqpchannel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qamqpchannel.cpp b/src/qamqpchannel.cpp index 9b3faa7..f20b1ae 100644 --- a/src/qamqpchannel.cpp +++ b/src/qamqpchannel.cpp @@ -33,7 +33,7 @@ void QAmqpChannelPrivate::init(int channel, QAmqpClient *c) client = c; needOpen = channel == -1 ? true : false; channelNumber = channel == -1 ? ++nextChannelNumber : channel; - nextChannelNumber = qMax(channelNumber, (nextChannelNumber + 1)); + nextChannelNumber = qMax(channelNumber, nextChannelNumber); } bool QAmqpChannelPrivate::_q_method(const QAmqpMethodFrame &frame)