Skip to content

Commit

Permalink
Fix websockets connections on Windows blocking subsequent connections.
Browse files Browse the repository at this point in the history
Closes #1934. Thanks to sectokia.
  • Loading branch information
ralight committed Dec 9, 2020
1 parent 0d74767 commit 9968e35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,7 @@
Broker:
- Fix websockets connections on Windows blocking subsequent connections.
Closes #1934.

Build:
- Fix cjson include paths.
- Fix build using WITH_TLS=no when the openssl headers aren't available.
Expand Down
11 changes: 7 additions & 4 deletions src/mux_poll.c
Expand Up @@ -89,7 +89,10 @@ int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_c
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return MOSQ_ERR_NOMEM;
}
memset(pollfds, -1, sizeof(struct pollfd)*pollfd_max);
memset(pollfds, 0, sizeof(struct pollfd)*pollfd_max);
for(i=0; i<pollfd_max; i++) {
pollfds[i].fd = INVALID_SOCKET;
}

for(i=0; i<listensock_count; i++){
pollfds[pollfd_index].fd = listensock[i].sock;
Expand All @@ -112,7 +115,7 @@ int mux_poll__add_out(struct mosquitto *context)
pollfds[context->pollfd_index].revents = 0;
}else{
for(i=0; i<pollfd_max; i++){
if(pollfds[i].fd == -1){
if(pollfds[i].fd == INVALID_SOCKET){
pollfds[i].fd = context->sock;
pollfds[i].events = POLLIN | POLLOUT;
pollfds[i].revents = 0;
Expand Down Expand Up @@ -142,7 +145,7 @@ int mux_poll__add_in(struct mosquitto *context)
pollfds[context->pollfd_index].revents = 0;
}else{
for(i=0; i<pollfd_max; i++){
if(pollfds[i].fd == -1){
if(pollfds[i].fd == INVALID_SOCKET){
pollfds[i].fd = context->sock;
pollfds[i].events = POLLIN;
pollfds[i].revents = 0;
Expand All @@ -158,7 +161,7 @@ int mux_poll__add_in(struct mosquitto *context)
int mux_poll__delete(struct mosquitto *context)
{
if(context->pollfd_index != -1){
pollfds[context->pollfd_index].fd = -1;
pollfds[context->pollfd_index].fd = INVALID_SOCKET;
pollfds[context->pollfd_index].events = 0;
pollfds[context->pollfd_index].revents = 0;
context->pollfd_index = -1;
Expand Down

0 comments on commit 9968e35

Please sign in to comment.