Codebase list libnet-dns-native-perl / 5a330e4
New upstream snapshot. Debian Janitor 2 years ago
4 changed file(s) with 81 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
33 "Oleg G <oleg@cpan.org>"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 7.1002, CPAN::Meta::Converter version 2.150005",
6 "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010",
77 "license" : [
88 "perl_5"
99 ],
1010 "meta-spec" : {
1111 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
12 "version" : "2"
12 "version" : 2
1313 },
1414 "name" : "Net-DNS-Native",
1515 "no_index" : {
4242 }
4343 },
4444 "version" : "0.22",
45 "x_serialization_backend" : "JSON::PP version 2.27300_01"
45 "x_serialization_backend" : "JSON::PP version 4.04"
4646 }
66 configure_requires:
77 ExtUtils::MakeMaker: '0'
88 dynamic_config: 1
9 generated_by: 'ExtUtils::MakeMaker version 7.1002, CPAN::Meta::Converter version 2.150005'
9 generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010'
1010 license: perl
1111 meta-spec:
1212 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2222 #if defined(WIN32) && !defined(UNDER_CE)
2323 # include <io.h>
2424 # define write _write
25 # define read _read
2625 #endif
2726
2827 // unnamed semaphores are not implemented in this POSIX compatible UNIX system
7170 int active_threads_cnt;
7271 int pool;
7372 char extra_thread;
73 int threads_limit;
74 char is_strict_limit;
7475 char notify_on_begin;
7576 int extra_threads_cnt;
7677 int busy_threads;
8485 char *host;
8586 char *service;
8687 struct addrinfo *hints;
87 char extra;
8888 char queued;
8989 DNS_result *res;
9090 } DNS_thread_arg;
102102 queue *DNS_instances = NULL;
103103
104104 void DNS_on_thread_finish(Net_DNS_Native *self) {
105 pthread_mutex_lock(&self->mutex);
106105 if (--self->active_threads_cnt == 0) {
107106 pthread_cond_signal(&self->cv);
108107 }
109 pthread_mutex_unlock(&self->mutex);
110108 }
111109
112110 void *DNS_getaddrinfo(void *v_arg) {
121119 if (self->notify_on_begin)
122120 write(arg->res->fd1, "1", 1);
123121 arg->res->gai_error = getaddrinfo(arg->host, arg->service, arg->hints, &arg->res->hostinfo);
122 #ifdef EAI_SYSTEM
124123 if (arg->res->gai_error == EAI_SYSTEM)
125124 arg->res->sys_error = errno;
125 #endif
126126
127127 pthread_mutex_lock(&self->mutex);
128128 arg->res->arg = arg;
129 if (arg->extra) self->extra_threads_cnt--;
129 if (!queued) self->extra_threads_cnt--;
130130 write(arg->res->fd1, "2", 1);
131 if (!queued) DNS_on_thread_finish(self);
131132 pthread_mutex_unlock(&self->mutex);
132133
133 if (!queued) DNS_on_thread_finish(self);
134134 return NULL;
135135 }
136136
144144 pthread_mutex_lock(&self->mutex);
145145 void *arg = queue_shift(self->in_queue);
146146 if (arg != NULL) self->busy_threads++;
147 else DNS_on_thread_finish(self);
147148 pthread_mutex_unlock(&self->mutex);
148149
149150 if (arg == NULL) {
150151 // this was request to quit thread
151 break;
152 return NULL;
152153 }
153154
154155 DNS_getaddrinfo(arg);
158159 pthread_mutex_unlock(&self->mutex);
159160 }
160161
161 DNS_on_thread_finish(self);
162162 return NULL;
163163 }
164164
172172 while (sem_wait(&self->semaphore) == 0) {
173173 pthread_mutex_lock(&self->mutex);
174174 void *arg = queue_shift(self->in_queue);
175 if (arg == NULL) DNS_on_thread_finish(self);
175176 pthread_mutex_unlock(&self->mutex);
176177
177178 if (arg == NULL) {
178 break;
179 return NULL;
179180 }
180181
181182 DNS_getaddrinfo(arg);
184185 if (!queue_size(self->in_queue) || (self->pool && self->busy_threads < self->pool)) {
185186 // extra worker may stop if queue is empty or there is free worker from the pool
186187 stop = 1;
188 DNS_on_thread_finish(self);
187189 }
188190 pthread_mutex_unlock(&self->mutex);
189191
190192 if (stop)
191 break;
192 }
193
194 DNS_on_thread_finish(self);
193 return NULL;
194 }
195
195196 return NULL;
196197 }
197198
346347
347348 int i, rc;
348349 self->pool = 0;
350 self->threads_limit = 0;
351 self->is_strict_limit = 0;
349352 self->notify_on_begin = 0;
350353 self->extra_thread = 0;
351354 self->active_threads_cnt = 0;
368371 else if (strEQ(opt, "extra_thread")) {
369372 self->extra_thread = SvIV(ST(i+1));
370373 }
374 else if (strEQ(opt, "threads_limit") || strEQ(opt, "threads_strict_limit")) {
375 self->threads_limit = SvIV(ST(i+1));
376 self->is_strict_limit = strEQ(opt, "threads_strict_limit");
377 }
371378 else if (strEQ(opt, "notify_on_begin")) {
372379 self->notify_on_begin = SvIV(ST(i+1));
373380 }
416423 #endif
417424 }
418425
419 if (self->pool) {
426 if (self->pool || self->threads_limit) {
420427 if (sem_init(&self->semaphore, 0, 0) != 0) {
421428 warn("sem_init(): %s", strerror(errno));
422429 goto FAIL;
423430 }
424431 sem_ok = 1;
425432
426 pthread_t tid;
427 int j = 0;
428 for (i=0; i<self->pool; i++) {
429 rc = pthread_create(&tid, &self->thread_attrs, DNS_pool_worker, (void*)self);
430 if (rc == 0) {
431 self->active_threads_cnt++;
432 j++;
433 if (self->pool) {
434 pthread_t tid;
435 int j = 0;
436 for (i=0; i<self->pool; i++) {
437 rc = pthread_create(&tid, &self->thread_attrs, DNS_pool_worker, (void*)self);
438 if (rc == 0) {
439 self->active_threads_cnt++;
440 j++;
441 }
442 else {
443 warn("Can't create thread #%d: %s", i+1, strerror(rc));
444 }
433445 }
434 else {
435 warn("Can't create thread #%d: %s", i+1, strerror(rc));
446
447 if (j == 0) {
448 goto FAIL;
436449 }
437 }
438
439 if (j == 0) {
440 goto FAIL;
441 }
442
443 self->pool = j;
450
451 self->pool = j;
452 }
453
444454 self->in_queue = queue_new();
445455 }
446456
476486 #endif
477487 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fd) != 0)
478488 croak("socketpair(): %s", strerror(errno));
479
489 #ifdef FD_CLOEXEC
480490 fcntl(fd[0], F_SETFD, FD_CLOEXEC);
481491 fcntl(fd[1], F_SETFD, FD_CLOEXEC);
482
492 #endif
483493 char *service = SvOK(sv_service) ? SvPV_nolen(sv_service) : "";
484494 struct addrinfo *hints = NULL;
485495
537547 arg->host = strlen(host) ? savepv(host) : NULL;
538548 arg->service = strlen(service) ? savepv(service) : NULL;
539549 arg->hints = hints;
540 arg->extra = 0;
541550 arg->queued = 0;
542551 arg->res = res;
543552
544553 pthread_mutex_lock(&self->mutex);
545554 DNS_free_timedout(self, 0);
546555 bstree_put(self->fd_map, fd[0], res);
556 char allow_extra_worker = 1;
557 if (self->threads_limit && self->active_threads_cnt == (self->is_strict_limit ? self->threads_limit : self->threads_limit + queue_size(self->tout_queue))) {
558 allow_extra_worker = 0;
559 }
560
547561 if (self->pool) {
548 if (self->busy_threads == self->pool && (self->extra_thread || queue_size(self->tout_queue) > self->extra_threads_cnt)) {
549 arg->extra = 1;
562 if (allow_extra_worker && self->busy_threads == self->pool && (self->extra_thread || queue_size(self->tout_queue) > self->extra_threads_cnt)) {
550563 self->extra_threads_cnt++;
551564 }
552565 else {
553566 arg->queued = 1;
554 queue_push(self->in_queue, arg);
555 sem_post(&self->semaphore);
556 }
557 }
558 pthread_mutex_unlock(&self->mutex);
559
560 if (!self->pool || arg->extra) {
567 allow_extra_worker = 0;
568 }
569 }
570
571 if (arg->queued || self->threads_limit) {
572 arg->queued = 1;
573 queue_push(self->in_queue, arg);
574 sem_post(&self->semaphore);
575 }
576 pthread_mutex_unlock(&self->mutex);
577
578 if (allow_extra_worker) {
561579 pthread_t tid;
562580
563581 pthread_mutex_lock(&self->mutex);
564 int rc = pthread_create(&tid, &self->thread_attrs, DNS_getaddrinfo, (void *)arg);
565 if (rc == 0) {
566 ++self->active_threads_cnt;
567 pthread_mutex_unlock(&self->mutex);
568 }
569 else {
582 ++self->active_threads_cnt;
583 pthread_mutex_unlock(&self->mutex);
584
585 int rc = self->threads_limit ?
586 pthread_create(&tid, &self->thread_attrs, DNS_extra_worker, (void *)self) :
587 pthread_create(&tid, &self->thread_attrs, DNS_getaddrinfo, (void *)arg);
588
589 if (rc != 0) {
590 pthread_mutex_lock(&self->mutex);
591 self->active_threads_cnt--;
570592 pthread_mutex_unlock(&self->mutex);
571593 if (arg->host) Safefree(arg->host);
572594 if (arg->service) Safefree(arg->service);
606628 SV *err = newSV(0);
607629 sv_setiv(err, (IV)res->gai_error);
608630 sv_setpv(err, res->gai_error ? gai_strerror(res->gai_error) : "");
609 if (res->gai_error == EAI_SYSTEM)
631 if (res->sys_error)
610632 sv_catpvf(err, " (%s)", strerror(res->sys_error));
611633 SvIOK_on(err);
612634 XPUSHs(sv_2mortal(err));
0 libnet-dns-native-perl (0.22+git20191101.1.5330c57-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Thu, 05 Aug 2021 14:26:57 -0000
5
06 libnet-dns-native-perl (0.22-2) unstable; urgency=medium
17
28 * Team upload.