Merge pull request #1660 from X-Ryl669/fixSelect

Fix select issue on FreeBSD.
This commit is contained in:
ejurgensen 2023-10-02 11:15:39 +02:00 committed by GitHub
commit c34acb16c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@
#include <net/if.h> #include <net/if.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
#include <event2/event.h> #include <event2/event.h>
@ -582,8 +583,7 @@ connection_test(int family, const char *address, const char *address_log, int po
struct addrinfo *ai; struct addrinfo *ai;
char strport[32]; char strport[32];
int sock; int sock;
fd_set fdset; struct pollfd fd;
struct timeval timeout = { MDNS_CONNECT_TEST_TIMEOUT, 0 };
socklen_t len; socklen_t len;
int flags; int flags;
int error; int error;
@ -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. // the case, but FreeBSD connect() sometimes returns immediate success.
if (ret != 0) if (ret != 0)
{ {
FD_ZERO(&fdset); // Use poll here since select requires using fdset that would be overflowed in FreeBSD
FD_SET(sock, &fdset); fd.fd = sock;
fd.events = POLLOUT;
ret = select(sock + 1, NULL, &fdset, NULL, &timeout); ret = poll(&fd, 1, MDNS_CONNECT_TEST_TIMEOUT * 1000);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_WARN, L_MDNS, "Connection test to %s:%d failed with select error: %s\n", address_log, port, strerror(errno)); DPRINTF(E_WARN, L_MDNS, "Connection test to %s:%d failed with select error: %s\n", address_log, port, strerror(errno));