Browse Source

Add a maxclients directive that stops accepting clients when there are too many

master
ckolivas 10 years ago
parent
commit
620d613d1a
  1. 1
      src/ckpool.c
  2. 2
      src/ckpool.h
  3. 12
      src/connector.c

1
src/ckpool.c

@ -997,6 +997,7 @@ static void parse_config(ckpool_t *ckp)
json_get_int64(&ckp->startdiff, json_conf, "startdiff");
json_get_int64(&ckp->maxdiff, json_conf, "maxdiff");
json_get_string(&ckp->logdir, json_conf, "logdir");
json_get_int(&ckp->maxclients, json_conf, "maxclients");
arr_val = json_object_get(json_conf, "proxy");
if (arr_val && json_is_array(arr_val)) {
int arr_size = json_array_size(arr_val);

2
src/ckpool.h

@ -113,6 +113,8 @@ struct ckpool_instance {
int oldconnfd;
/* Should we inherit a running instance's socket and shut it down */
bool handover;
/* How many clients maximum to accept before rejecting further */
int maxclients;
/* Logger message queue NOTE: Unique per process */
ckmsgq_t *logger;

12
src/connector.c

@ -90,8 +90,18 @@ static pthread_cond_t sender_cond;
static int accept_client(conn_instance_t *ci)
{
client_instance_t *client, *old_client;
ckpool_t *ckp = ci->pi->ckp;
int fd, port, no_clients;
socklen_t address_len;
int fd, port;
ck_rlock(&ci->lock);
no_clients = HASH_COUNT(clients);
ck_runlock(&ci->lock);
if (ckp->maxclients && no_clients >= ckp->maxclients) {
LOGWARNING("Server full with %d clients", no_clients);
return 0;
}
client = ckzalloc(sizeof(client_instance_t));
address_len = sizeof(client->address);

Loading…
Cancel
Save