Fix high CPU use on slow TLS connect.

Closes #2794. Thanks to Evgeny S.
This commit is contained in:
Roger A. Light 2023-04-27 23:25:52 +01:00
parent 3c51816009
commit 269756a171
3 changed files with 14 additions and 22 deletions

View File

@ -17,6 +17,7 @@ Client library:
problem of the client OS sleeping and the client hence not being able to problem of the client OS sleeping and the client hence not being able to
calculate the actual time for keepalive purposes. Closes #2760. calculate the actual time for keepalive purposes. Closes #2760.
- Fix default settings incorrectly allowing TLS v1.1. Closes #2722. - Fix default settings incorrectly allowing TLS v1.1. Closes #2722.
- Fix high CPU use on slow TLS connect. Closes #2794.
Clients: Clients:
- Fix incorrect topic-alias property value in mosquitto_sub json output. - Fix incorrect topic-alias property value in mosquitto_sub json output.

View File

@ -63,20 +63,22 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
if(mosq->sock != INVALID_SOCKET){ if(mosq->sock != INVALID_SOCKET){
maxfd = mosq->sock; maxfd = mosq->sock;
FD_SET(mosq->sock, &readfds); FD_SET(mosq->sock, &readfds);
pthread_mutex_lock(&mosq->current_out_packet_mutex); if(mosq->want_write){
pthread_mutex_lock(&mosq->out_packet_mutex);
if(mosq->out_packet || mosq->current_out_packet){
FD_SET(mosq->sock, &writefds); FD_SET(mosq->sock, &writefds);
} }else{
#ifdef WITH_TLS #ifdef WITH_TLS
if(mosq->ssl){ if(mosq->ssl == NULL || SSL_is_init_finished(mosq->ssl))
if(mosq->want_write){ #endif
FD_SET(mosq->sock, &writefds); {
pthread_mutex_lock(&mosq->current_out_packet_mutex);
pthread_mutex_lock(&mosq->out_packet_mutex);
if(mosq->out_packet || mosq->current_out_packet){
FD_SET(mosq->sock, &writefds);
}
pthread_mutex_unlock(&mosq->out_packet_mutex);
pthread_mutex_unlock(&mosq->current_out_packet_mutex);
} }
} }
#endif
pthread_mutex_unlock(&mosq->out_packet_mutex);
pthread_mutex_unlock(&mosq->current_out_packet_mutex);
}else{ }else{
#ifdef WITH_SRV #ifdef WITH_SRV
if(mosq->achan){ if(mosq->achan){

View File

@ -332,18 +332,7 @@ int mosquitto_socket(struct mosquitto *mosq)
bool mosquitto_want_write(struct mosquitto *mosq) bool mosquitto_want_write(struct mosquitto *mosq)
{ {
bool result = false; return mosq->out_packet || mosq->current_out_packet || mosq->want_write;
if(mosq->out_packet || mosq->current_out_packet){
result = true;
}
#ifdef WITH_TLS
if(mosq->ssl){
if (mosq->want_write) {
result = true;
}
}
#endif
return result;
} }