Commits

Roger Light committed 19c2f13

Don't always attempt to call read() for SSL clients, irrespective of whether
they were ready to read or not. Reduces syscalls significantly.

Thanks to Karl Palsson.

Comments (0)

Files changed (5)

 - Fix possible memory leak in C/C++ library when communicating with
   a broker that doesn't follow the spec.
+- Don't always attempt to call read() for SSL clients, irrespective of whether
+  they were ready to read or not. Reduces syscalls significantly.
 
 1.2.2 - 20131021
 ================

lib/mosquitto_internal.h

 	char *tls_psk_identity;
 	bool tls_insecure;
 #endif
-	bool want_read;
 	bool want_write;
 #if defined(WITH_THREADING) && !defined(WITH_BROKER)
 	pthread_mutex_t callback_mutex;
 		if(ret != 1){
 			ret = SSL_get_error(mosq->ssl, ret);
 			if(ret == SSL_ERROR_WANT_READ){
-				mosq->want_read = true;
+				/* We always try to read anyway */
 			}else if(ret == SSL_ERROR_WANT_WRITE){
 				mosq->want_write = true;
 			}else{
 			err = SSL_get_error(mosq->ssl, ret);
 			if(err == SSL_ERROR_WANT_READ){
 				ret = -1;
-				mosq->want_read = true;
 				errno = EAGAIN;
 			}else if(err == SSL_ERROR_WANT_WRITE){
 				ret = -1;
 			err = SSL_get_error(mosq->ssl, ret);
 			if(err == SSL_ERROR_WANT_READ){
 				ret = -1;
-				mosq->want_read = true;
 				errno = EAGAIN;
 			}else if(err == SSL_ERROR_WANT_WRITE){
 				ret = -1;
 			assert(pollfds[db->contexts[i]->pollfd_index].fd == db->contexts[i]->sock);
 #ifdef WITH_TLS
 			if(pollfds[db->contexts[i]->pollfd_index].revents & POLLIN ||
-					db->contexts[i]->want_read ||
 					(db->contexts[i]->ssl && db->contexts[i]->state == mosq_cs_new)){
 #else
 			if(pollfds[db->contexts[i]->pollfd_index].revents & POLLIN){
 						}
 						SSL_set_ex_data(new_context->ssl, tls_ex_index_context, new_context);
 						SSL_set_ex_data(new_context->ssl, tls_ex_index_listener, &db->config->listeners[i]);
-						new_context->want_read = true;
 						new_context->want_write = true;
 						bio = BIO_new_socket(new_sock, BIO_NOCLOSE);
 						SSL_set_bio(new_context->ssl, bio, bio);
 						if(rc != 1){
 							rc = SSL_get_error(new_context->ssl, rc);
 							if(rc == SSL_ERROR_WANT_READ){
-								new_context->want_read = true;
+								/* We always want to read. */
 							}else if(rc == SSL_ERROR_WANT_WRITE){
 								new_context->want_write = true;
 							}else{