From 00491da0311706b8e8bd018203cf499bccb12f45 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 14 Jan 2016 21:15:02 +0000 Subject: [PATCH] [485143] Fix detection of broken connections on Windows. Thanks to Pierre-Yves Boisbunon. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=485143 --- ChangeLog.txt | 3 +++ src/loop.c | 24 +++++------------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a83bf84f..5300e7ba 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +Broker: +- Fix detection of broken connections on Windows. Closes #485143. + Client library: - mosq->want_write should be cleared immediately before a call to SSL_write, to allow clients using mosquitto_want_write() to get accurate results. diff --git a/src/loop.c b/src/loop.c index a5f624b3..6a9f6e6b 100644 --- a/src/loop.c +++ b/src/loop.c @@ -56,7 +56,6 @@ extern int run; extern int g_clients_expired; #endif -static void loop_handle_errors(struct mosquitto_db *db, struct pollfd *pollfds); static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pollfds); #ifdef WITH_WEBSOCKETS @@ -322,7 +321,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li fdcount = WSAPoll(pollfds, pollfd_index, 100); #endif if(fdcount == -1){ - loop_handle_errors(db, pollfds); + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error in poll: %s.", strerror(errno)); }else{ loop_handle_reads_writes(db, pollfds); @@ -437,23 +436,6 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context) } } -/* Error ocurred, probably an fd has been closed. - * Loop through and check them all. - */ -static void loop_handle_errors(struct mosquitto_db *db, struct pollfd *pollfds) -{ - struct mosquitto *context, *ctxt_tmp; - - HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp){ - if(context->pollfd_index < 0){ - continue; - } - - if(pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL)){ - do_disconnect(db, context); - } - } -} static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pollfds) { @@ -467,6 +449,10 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol } assert(pollfds[context->pollfd_index].fd == context->sock); + if(pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL)){ + do_disconnect(db, context); + continue; + } #ifdef WITH_TLS if(pollfds[context->pollfd_index].revents & POLLOUT || context->want_write ||