|
1 | 1 | // |
2 | 2 | // DNS-SD API functions for CUPS. |
3 | 3 | // |
4 | | -// Copyright © 2022 by OpenPrinting. |
| 4 | +// Copyright © 2022-2023 by OpenPrinting. |
5 | 5 | // |
6 | 6 | // Licensed under Apache License v2.0. See the file "LICENSE" for more |
7 | 7 | // information. |
@@ -409,12 +409,14 @@ cupsDNSSDDelete(cups_dnssd_t *dnssd) // I - DNS-SD context |
409 | 409 |
|
410 | 410 | #ifdef HAVE_MDNSRESPONDER |
411 | 411 | cupsThreadCancel(dnssd->monitor); |
| 412 | + cupsThreadWait(dnssd->monitor); |
412 | 413 | DNSServiceRefDeallocate(dnssd->ref); |
413 | 414 |
|
414 | 415 | #elif _WIN32 |
415 | 416 |
|
416 | 417 | #else // HAVE_AVAHI |
417 | 418 | cupsThreadCancel(dnssd->monitor); |
| 419 | + cupsThreadWait(dnssd->monitor); |
418 | 420 | avahi_simple_poll_free(dnssd->poll); |
419 | 421 | #endif // HAVE_MDNSRESPONDER |
420 | 422 |
|
@@ -562,7 +564,6 @@ cupsDNSSDNew( |
562 | 564 | return (NULL); |
563 | 565 | } |
564 | 566 |
|
565 | | - cupsThreadDetach(dnssd->monitor); |
566 | 567 | DEBUG_printf(("2cupsDNSSDNew: dnssd->monitor=%p", (void *)dnssd->monitor)); |
567 | 568 |
|
568 | 569 | #elif _WIN32 |
@@ -603,7 +604,6 @@ cupsDNSSDNew( |
603 | 604 | return (NULL); |
604 | 605 | } |
605 | 606 |
|
606 | | - cupsThreadDetach(dnssd->monitor); |
607 | 607 | DEBUG_printf(("2cupsDNSSDNew: dnssd->monitor=%p", (void *)dnssd->monitor)); |
608 | 608 | #endif // HAVE_MDNSRESPONDER |
609 | 609 |
|
@@ -1631,9 +1631,21 @@ static void * // O - Return value (always `NULL`) |
1631 | 1631 | mdns_monitor(cups_dnssd_t *dnssd) // I - DNS-SD context |
1632 | 1632 | { |
1633 | 1633 | DNSServiceErrorType error; // Current error |
| 1634 | + struct pollfd polldata; // Polling data |
| 1635 | + |
| 1636 | + polldata.fd = DNSServiceRefSockFD(dnssd->ref); |
| 1637 | + polldata.events = POLLERR | POLLHUP | POLLIN; |
1634 | 1638 |
|
1635 | 1639 | for (;;) |
1636 | 1640 | { |
| 1641 | +# ifndef _WIN32 |
| 1642 | + if (poll(&polldata, 1, 1000) < 0 && errno != EINTR && errno != EAGAIN) |
| 1643 | + break; |
| 1644 | + |
| 1645 | + if (!(polldata.revents & POLLIN)) |
| 1646 | + continue; |
| 1647 | +# endif // !_WIN32 |
| 1648 | + |
1637 | 1649 | if ((error = DNSServiceProcessResult(dnssd->ref)) != kDNSServiceErr_NoError) |
1638 | 1650 | { |
1639 | 1651 | report_error(dnssd, "Unable to read response from DNS-SD service: %s", mdns_strerror(error)); |
|
0 commit comments