Skip to content

Commit

Permalink
Merge pull request #1660 from X-Ryl669/fixSelect
Browse files Browse the repository at this point in the history
Fix select issue on FreeBSD.
  • Loading branch information
ejurgensen authored Oct 2, 2023
2 parents 8528073 + ab790c2 commit c34acb1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/mdns_avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <net/if.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>

#include <event2/event.h>

Expand Down Expand Up @@ -582,8 +583,7 @@ connection_test(int family, const char *address, const char *address_log, int po
struct addrinfo *ai;
char strport[32];
int sock;
fd_set fdset;
struct timeval timeout = { MDNS_CONNECT_TEST_TIMEOUT, 0 };
struct pollfd fd;
socklen_t len;
int flags;
int error;
Expand Down Expand Up @@ -639,10 +639,11 @@ connection_test(int family, const char *address, const char *address_log, int po
// the case, but FreeBSD connect() sometimes returns immediate success.
if (ret != 0)
{
FD_ZERO(&fdset);
FD_SET(sock, &fdset);

ret = select(sock + 1, NULL, &fdset, NULL, &timeout);
// Use poll here since select requires using fdset that would be overflowed in FreeBSD
fd.fd = sock;
fd.events = POLLOUT;

ret = poll(&fd, 1, MDNS_CONNECT_TEST_TIMEOUT * 1000);
if (ret < 0)
{
DPRINTF(E_WARN, L_MDNS, "Connection test to %s:%d failed with select error: %s\n", address_log, port, strerror(errno));
Expand Down

0 comments on commit c34acb1

Please sign in to comment.