Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing an issue of max message identifier #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/paho-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function onMessageArrived(message) {
/* The largest message identifier allowed, may not be larger than 2**16 but
* if set smaller reduces the maximum number of outbound messages allowed.
*/
ClientImpl.prototype.maxMessageIdentifier = 65536;
ClientImpl.prototype.maxMessageIdentifier = 65535;
ClientImpl.prototype.connectOptions = null;
ClientImpl.prototype.hostIndex = null;
ClientImpl.prototype.onConnected = null;
Expand Down Expand Up @@ -1187,20 +1187,20 @@ function onMessageArrived(message) {
*/
ClientImpl.prototype._requires_ack = function (wireMessage) {
var messageCount = Object.keys(this._sentMessages).length;
if (messageCount > this.maxMessageIdentifier)
if (messageCount >= this.maxMessageIdentifier)
throw Error ("Too many messages:"+messageCount);

while(this._sentMessages[this._message_identifier] !== undefined) {
this._message_identifier++;
if (this._message_identifier === this.maxMessageIdentifier) {
this._message_identifier = 1;
}
}
wireMessage.messageIdentifier = this._message_identifier;
this._sentMessages[wireMessage.messageIdentifier] = wireMessage;
if (wireMessage.type === MESSAGE_TYPE.PUBLISH) {
this.store("Sent:", wireMessage);
}
if (this._message_identifier === this.maxMessageIdentifier) {
this._message_identifier = 1;
}
};

/**
Expand Down