Merge pull request #571 from kevinresol/patch-1

Support pre-connected Client
This commit is contained in:
Nick O'Leary 2019-11-25 11:21:09 +00:00 committed by GitHub
commit 2b83aa0804
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()) { if (!connected()) {
int result = 0; int result = 0;
if (domain != NULL) {
result = _client->connect(this->domain, this->port); if(_client->connected()) {
result = 1;
} else { } 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) { if (result == 1) {
nextMsgId = 1; nextMsgId = 1;
// Leave room in the buffer for header and variable length field // Leave room in the buffer for header and variable length field
@ -609,6 +615,8 @@ boolean PubSubClient::connected() {
_client->flush(); _client->flush();
_client->stop(); _client->stop();
} }
} else {
return this->_state == MQTT_CONNECTED;
} }
} }
return rc; return rc;