From 8f7e1bde283ef9ed30230e5c39f0ec185253c7fb Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Thu, 4 Apr 2024 16:26:58 -0400 Subject: [PATCH] natpmp: use winsock poll on Windows Change-Id: I7b4ee7d3bd2b409ad098515c2a9c61eb67ce0833 --- src/upnp/protocol/natpmp/nat_pmp.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/upnp/protocol/natpmp/nat_pmp.cpp b/src/upnp/protocol/natpmp/nat_pmp.cpp index ac607c9..77a3f4e 100644 --- a/src/upnp/protocol/natpmp/nat_pmp.cpp +++ b/src/upnp/protocol/natpmp/nat_pmp.cpp @@ -17,7 +17,19 @@ #include "nat_pmp.h" #if HAVE_LIBNATPMP +#ifdef _WIN32 +// On Windows we assume WSAStartup is called during DHT initialization +#include <winsock2.h> +#include <ws2tcpip.h> +#else #include <poll.h> +#endif + +#ifdef _WIN32 +#define _poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) +#else +#define _poll(fds, nfds, timeout) poll(fds, nfds, timeout) +#endif namespace dhtnet { namespace upnp { @@ -340,8 +352,9 @@ NatPmp::readResponse(natpmp_t& handle, natpmpresp_t& response) struct timeval timeout; getnatpmprequesttimeout(&handle, &timeout); uint64_t millis = (timeout.tv_sec * (uint64_t)1000) + (timeout.tv_usec / 1000); + // Wait for data. - if (poll(&fds, 1, millis) == -1) { + if (_poll(&fds, 1, millis) == -1) { err = NATPMP_ERR_SOCKETERROR; break; } -- GitLab