diff options
author | Christian Hesse <mail@eworm.de> | 2015-12-12 12:09:52 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-12-12 12:09:52 +0100 |
commit | d7e41016af9ba005390469cabd8e5cda1360b90e (patch) | |
tree | 663682de2fbfa698e1a938600570db03a97391b2 /pacredir.c | |
parent | e7afd8bab7e52a1dd53b900fd93fbd97092278d8 (diff) | |
download | paccache-d7e41016af9ba005390469cabd8e5cda1360b90e.tar.gz paccache-d7e41016af9ba005390469cabd8e5cda1360b90e.tar.zst |
allow to limit the number of query threads
Diffstat (limited to 'pacredir.c')
-rw-r--r-- | pacredir.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -20,6 +20,7 @@ const static struct option options_long[] = { /* global variables */ struct hosts * hosts = NULL; struct ignore_interfaces * ignore_interfaces = NULL; +int max_threads = 0; static AvahiSimplePoll *simple_poll = NULL; uint8_t verbose = 0; @@ -368,6 +369,12 @@ static int ahc_echo(void * cls, continue; } + /* Check for limit on threads */ + if (max_threads > 0 && req_count + 1 >= max_threads) { + write_log(stdout, "Hit hard limit for max threads (%d), not doing more requests\n", max_threads); + break; + } + /* This is multi-threading code! * Pointer to struct request does not work as realloc can relocate the data. * We need a pointer to pointer to struct request, store the addresses in @@ -544,8 +551,13 @@ int main(int argc, char ** argv) { /* parse config file */ if ((ini = iniparser_load(CONFIGFILE)) == NULL) { write_log(stderr, "cannot parse file " CONFIGFILE ", continue anyway\n"); - /* continue anyway, there is nothing essential in the config file */ + /* continue anyway, there is nothing essential in the config file */ } else { + /* get max threads */ + max_threads = iniparser_getint(ini, "general:max threads", max_threads); + if (verbose > 0) + write_log(stdout, "Limiting number of threads to a maximum of %d\n", max_threads); + /* store interfaces to ignore */ if ((inistring = iniparser_getstring(ini, "general:ignore interfaces", NULL)) != NULL) { values = strdup(inistring); |