mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-02-06 02:52:07 +08:00
Fix connection problems when using mosquitto_connect_async().
The connection wouldn't always complete if mosquitto_loop_start() was called before mosquitto_connect_async(). Closes #848. Thanks to Ian Gough. Bug: https://github.com/eclipse/mosquitto/issues/848 Signed-off-by: Roger A. Light <roger@atchoo.org>
This commit is contained in:
@@ -21,6 +21,8 @@ Library:
|
||||
- Fix some places where return codes were incorrect, including to the
|
||||
on_disconnect() callback. This has resulted in two new error codes,
|
||||
MOSQ_ERR_KEEPALIVE and MOSQ_ERR_LOOKUP.
|
||||
- Fix connection problems when mosquitto_loop_start() was called before
|
||||
mosquitto_connect_async(). Closes #848.
|
||||
|
||||
|
||||
1.5 - 20180502
|
||||
|
||||
@@ -178,6 +178,9 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking)
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
pthread_mutex_lock(&mosq->state_mutex);
|
||||
mosq->state = mosq_cs_connecting;
|
||||
pthread_mutex_unlock(&mosq->state_mutex);
|
||||
rc = net__socket_connect(mosq, mosq->host, mosq->port, mosq->bind_address, blocking);
|
||||
}
|
||||
if(rc>0){
|
||||
|
||||
@@ -107,6 +107,7 @@ enum mosquitto_client_state {
|
||||
mosq_cs_socks5_userpass_reply = 13,
|
||||
mosq_cs_socks5_send_userpass = 14,
|
||||
mosq_cs_expiring = 15,
|
||||
mosq_cs_connecting = 16,
|
||||
};
|
||||
|
||||
enum mosquitto__protocol {
|
||||
|
||||
@@ -79,15 +79,27 @@ int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
|
||||
void *mosquitto__thread_main(void *obj)
|
||||
{
|
||||
struct mosquitto *mosq = obj;
|
||||
int state;
|
||||
|
||||
if(!mosq) return NULL;
|
||||
|
||||
pthread_mutex_lock(&mosq->state_mutex);
|
||||
if(mosq->state == mosq_cs_connect_async){
|
||||
do{
|
||||
pthread_mutex_lock(&mosq->state_mutex);
|
||||
state = mosq->state;
|
||||
pthread_mutex_unlock(&mosq->state_mutex);
|
||||
if(state == mosq_cs_new){
|
||||
#ifdef WIN32
|
||||
Sleep(10);
|
||||
#else
|
||||
usleep(10000);
|
||||
#endif
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while(1);
|
||||
|
||||
if(state == mosq_cs_connect_async){
|
||||
mosquitto_reconnect(mosq);
|
||||
}else{
|
||||
pthread_mutex_unlock(&mosq->state_mutex);
|
||||
}
|
||||
|
||||
if(!mosq->keepalive){
|
||||
|
||||
Reference in New Issue
Block a user