Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum connections for websockets listener #271

Merged
merged 1 commit into from
Sep 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Maximum connections for websockets listener
Check current number of connections before accepting new websockets clients.

Signed-off-by: tucic <[email protected]>
  • Loading branch information
tucic committed Sep 16, 2016
commit 393d8bce6f3d966e1ace9fa5144d9ed170c60624
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