diff --git a/src/connector.c b/src/connector.c index 3ce2bb2d..f78cb9c8 100644 --- a/src/connector.c +++ b/src/connector.c @@ -298,25 +298,34 @@ static int accept_client(cdata_t *cdata, const int epfd, const uint64_t server) return 1; } +static int __drop_client(cdata_t *cdata, client_instance_t *client) +{ + int ret = -1; + + if (client->invalid) + goto out; + client->invalid = true; + ret = client->fd; + Close(client->fd); + epoll_ctl(cdata->epfd, EPOLL_CTL_DEL, ret, NULL); + HASH_DEL(cdata->clients, client); + DL_APPEND(cdata->dead_clients, client); + /* This is the reference to this client's presence in the + * epoll list. */ + __dec_instance_ref(client); + cdata->dead_generated++; +out: + return ret; +} + /* Client must hold a reference count */ static int drop_client(cdata_t *cdata, client_instance_t *client) { - int64_t client_id = 0; + int64_t client_id = client->id; int fd = -1; ck_wlock(&cdata->lock); - if (!client->invalid) { - client->invalid = true; - client_id = client->id; - fd = client->fd; - epoll_ctl(cdata->epfd, EPOLL_CTL_DEL, fd, NULL); - HASH_DEL(cdata->clients, client); - DL_APPEND(cdata->dead_clients, client); - /* This is the reference to this client's presence in the - * epoll list. */ - __dec_instance_ref(client); - cdata->dead_generated++; - } + fd = __drop_client(cdata, client); ck_wunlock(&cdata->lock); if (fd > -1) @@ -388,6 +397,17 @@ static int invalidate_client(ckpool_t *ckp, cdata_t *cdata, client_instance_t *c return ret; } +static void drop_all_clients(cdata_t *cdata) +{ + client_instance_t *client, *tmp; + + ck_wlock(&cdata->lock); + HASH_ITER(hh, cdata->clients, client, tmp) { + __drop_client(cdata, client); + } + ck_wunlock(&cdata->lock); +} + static void send_client(cdata_t *cdata, int64_t id, char *buf); /* Look for shares being submitted via a redirector and add them to a linked @@ -1116,7 +1136,8 @@ retry: } else if (cmdmatch(buf, "reject")) { LOGDEBUG("Connector received reject signal"); cdata->accept = false; - send_proc(ckp->stratifier, "dropall"); + if (ckp->passthrough) + drop_all_clients(cdata); } else if (cmdmatch(buf, "stats")) { char *msg; diff --git a/src/generator.c b/src/generator.c index 1f832ab8..3680535a 100644 --- a/src/generator.c +++ b/src/generator.c @@ -2302,7 +2302,7 @@ static proxy_instance_t *wait_best_proxy(ckpool_t *ckp, gdata_t *gdata) break; /* Send reject message if we are unable to find an active * proxy for more than 5 seconds */ - if (!((++retries) % 5)) + if (!((retries++) % 5)) send_proc(ckp->connector, "reject"); sleep(1); }