Support pre-connected Client

This commit is contained in:
Kevin Leung 2019-02-04 00:07:05 +08:00 committed by GitHub
parent 26ce89fa47
commit a4f7821a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,11 +121,17 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
if (!connected()) {
int result = 0;
if (domain != NULL) {
result = _client->connect(this->domain, this->port);
if(_client->connected()) {
result = 1;
} else {
result = _client->connect(this->ip, this->port);
if (domain != NULL) {
result = _client->connect(this->domain, this->port);
} else {
result = _client->connect(this->ip, this->port);
}
}
if (result == 1) {
nextMsgId = 1;
// Leave room in the buffer for header and variable length field
@ -610,6 +616,8 @@ boolean PubSubClient::connected() {
_client->flush();
_client->stop();
}
} else {
return this->_state == MQTT_CONNECTED;
}
}
return rc;