From 408972ddc1fe8fa0ac37f40c7bc446df7372633b Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Fri, 23 Jun 2017 23:30:57 +0200 Subject: [PATCH] Fix two issues with Websocket (#472) * Websocket were always marked as "want_write" (even if they only want to read, or worse want nothing). * Websocket FD was read twice in some case (when socket recv queue was larger that size read by libwebsocket) Signed-off-by: Pierre Fersing --- src/loop.c | 6 ++++++ src/websockets.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/loop.c b/src/loop.c index 0828c40c..6f863728 100644 --- a/src/loop.c +++ b/src/loop.c @@ -525,6 +525,12 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol if(context->pollfd_index < 0){ continue; } +#ifdef WITH_WEBSOCKETS + if(context->wsi){ + // Websocket are already handled above + continue; + } +#endif #ifdef WITH_TLS if(pollfds[context->pollfd_index].revents & POLLIN || diff --git a/src/websockets.c b/src/websockets.c index 9923a287..dde0c9cc 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -593,7 +593,7 @@ static int callback_http(struct libwebsocket_context *context, case LWS_CALLBACK_DEL_POLL_FD: case LWS_CALLBACK_CHANGE_MODE_POLL_FD: HASH_FIND(hh_sock, db->contexts_by_sock, &pollargs->fd, sizeof(pollargs->fd), mosq); - if(mosq){ + if(mosq && (pollargs->events & POLLOUT)){ mosq->ws_want_write = true; } break;