Skip to content

Commit

Permalink
Fix TLS connections when using an external event loop.
Browse files Browse the repository at this point in the history
Affects the use of mosquitto_loop_read() and mosquitto_write().
Closes #990.
  • Loading branch information
ralight committed Nov 7, 2018
1 parent b803b40 commit 71b8c4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Broker:

Library:
- Fix memory leak that occurred if mosquitto_reconnect() was used when TLS
errors were present. Closes #592.
errors were present. Closes #592.
- Fix TLS connections when using an external event loop with
mosquitto_loop_read() and mosquitto_write(). Closes #990.

Build:
- Fix clients not being compiled with threading support when using CMake.
Expand Down
26 changes: 12 additions & 14 deletions lib/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,12 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}else{
if(mosq->sock != INVALID_SOCKET){
if(FD_ISSET(mosq->sock, &readfds)){
#ifdef WITH_TLS
if(mosq->want_connect){
rc = net__socket_connect_tls(mosq);
if(rc) return rc;
}else
#endif
{
do{
rc = mosquitto_loop_read(mosq, max_packets);
if(rc || mosq->sock == INVALID_SOCKET){
return rc;
}
}while(SSL_DATA_PENDING(mosq));
}
do{
rc = mosquitto_loop_read(mosq, max_packets);
if(rc || mosq->sock == INVALID_SOCKET){
return rc;
}
}while(SSL_DATA_PENDING(mosq));
}
if(mosq->sockpairR != INVALID_SOCKET && FD_ISSET(mosq->sockpairR, &readfds)){
#ifndef WIN32
Expand Down Expand Up @@ -354,6 +346,12 @@ int mosquitto_loop_read(struct mosquitto *mosq, int max_packets)
int i;
if(max_packets < 1) return MOSQ_ERR_INVAL;

#ifdef WITH_TLS
if(mosq->want_connect){
return net__socket_connect_tls(mosq);
}
#endif

pthread_mutex_lock(&mosq->out_message_mutex);
max_packets = mosq->out_queue_len;
pthread_mutex_unlock(&mosq->out_message_mutex);
Expand Down

0 comments on commit 71b8c4d

Please sign in to comment.