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

add mqtt error type #136

Closed
wants to merge 3 commits into from
Closed

add mqtt error type #136

wants to merge 3 commits into from

Conversation

yinbaoqiang
Copy link

add mqtt error type , Re-edit for pull #135 .
Solve the #133 problem.

Add enum ClientError element .
MqttUnacceptableProtocolVersionError=1<<16, MqttIdentifierRejectedError, MqttServerUnavailableError, MqttVadUserNameOrPasswordError, MqttNotAuthorizedError

Modify the handleConnack ack !=0 to issue an error message number.
`void QMQTT::ClientPrivate::handleConnack(const quint8 ack)
{
Q_Q(Client);
if (ack==0) {
emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));

}`

@mwallnoefer
Copy link
Collaborator

I am okay with this change, it seems to address the concerns.
@ejvr + @KonstantinRitt ?

@@ -67,6 +67,16 @@ enum ConnectionState
STATE_CONNECTED,
STATE_DISCONNECTED
};
namespace MqttError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need in namespace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without namespace, the same element between ClientError and MqttError will conflict

_mqttErrorHash.insert(MqttError::MqttServerUnavailableError, MqttServerUnavailableError);
_mqttErrorHash.insert(MqttError::MqttVadUserNameOrPasswordError, MqttVadUserNameOrPasswordError);
_mqttErrorHash.insert(MqttError::MqttNotAuthorizedError, MqttNotAuthorizedError);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waste

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintain the same processing mode as QAbstractSocket.

@@ -39,6 +39,7 @@
#include <QSslConfiguration>
#include <QSslKey>
#endif // QT_NO_SSL
#include <QDebug>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless

if (ack==0) {
emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch-case loop would be a lot cheaper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emits error() right after connected(). did you ever test your change-set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Ask==0 is the most common case, using "if" is more efficient, and the error is relatively small.
  2. There is no problem with my program.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to me the if needs to be changed to something likes this:

if (ack==0)
  emit q->connected();
else
  emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwallnoefer You're right. We don't want to emit the error signal if there is no error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KonstantinRitt A switch-case would be cheaper indeed. But I guess @yinbaoqiang used this approach, because it was already used for the socket errors. I would accept this pull request first and create the switch-case later.

emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waste

@@ -440,8 +440,7 @@ void QMQTT::ClientPrivate::handleConnack(const quint8 ack)
if (ack==0) {
emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));

emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz squash with previous commit

@@ -39,7 +39,6 @@
#include <QSslConfiguration>
#include <QSslKey>
#endif // QT_NO_SSL
#include <QDebug>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz squash with previous commit

Copy link
Contributor

@ejvr ejvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a useful fix to me.

@@ -67,6 +67,16 @@ enum ConnectionState
STATE_CONNECTED,
STATE_DISCONNECTED
};
namespace MqttError {
enum MqttError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal enum, and should not be part of the public interface. Move it to qmqtt_client_p.cpp where it is used.
The name of the first value of enum MqttError is incorrect (the value indicates that the connection is OK). It is not used as well, so remove it. This will also remove the need to the MqttError namespace.

if (ack==0) {
emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwallnoefer You're right. We don't want to emit the error signal if there is no error.

if (ack==0) {
emit q->connected();
}
emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KonstantinRitt A switch-case would be cheaper indeed. But I guess @yinbaoqiang used this approach, because it was already used for the socket errors. I would accept this pull request first and create the switch-case later.

ejvr added a commit to ejvr/qmqtt that referenced this pull request May 6, 2018
@ejvr ejvr mentioned this pull request May 7, 2018
mwallnoefer added a commit that referenced this pull request May 7, 2018
Cleanup of pull request #136
@mwallnoefer
Copy link
Collaborator

Closed in favour of pull request #138.

@mwallnoefer mwallnoefer closed this May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants