Skip to content

Commit

Permalink
Maximum connections for websockets listener (#271)
Browse files Browse the repository at this point in the history
Check current number of connections before accepting new websockets clients.

Signed-off-by: tucic <[email protected]>
  • Loading branch information
tucic authored and ralight committed Sep 29, 2016
1 parent 7621260 commit f272e2e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ static int callback_mqtt(struct libwebsocket_context *context,
}
}
}

if(!mosq->listener){
_mosquitto_free(mosq);
return -1;
}
#if !defined(LWS_LIBRARY_VERSION_NUMBER)
mosq->ws_context = context;
#endif
Expand All @@ -209,6 +212,12 @@ static int callback_mqtt(struct libwebsocket_context *context,
u->mosq = NULL;
return -1;
}
if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
_mosquitto_free(mosq);
u->mosq = NULL;
return -1;
}
break;

case LWS_CALLBACK_CLOSED:
Expand Down

0 comments on commit f272e2e

Please sign in to comment.