diff --git a/examples/mqttnet.c b/examples/mqttnet.c index acd9d3340..359b59382 100644 --- a/examples/mqttnet.c +++ b/examples/mqttnet.c @@ -287,6 +287,7 @@ static int NetConnect(void *context, const char* host, word16 port, if (errno == EINPROGRESS || errno == EWOULDBLOCK) { return MQTT_CODE_CONTINUE; } + SOCK_CLOSE(sock->fd); /* Show error */ PRINTF("NetConnect: Rc=%d, ErrNo=%d", rc, errno); @@ -540,7 +541,8 @@ static int NetConnect(void *context, const char* host, word16 port, exit: /* Show error */ - if (rc != 0) { + if ((rc != 0) && (rc != MQTT_CODE_CONTINUE)) { + SOCK_CLOSE(sock->fd); PRINTF("NetConnect: Rc=%d, SoErr=%d", rc, so_error); } @@ -630,7 +632,7 @@ static int SN_NetConnect(void *context, const char* host, word16 port, exit: /* Show error */ - if (rc != 0) { + if ((rc != 0) && (rc != MQTT_CODE_CONTINUE)) { SOCK_CLOSE(sock->fd); PRINTF("NetConnect: Rc=%d, SoErr=%d", rc, so_error); }