X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Ftcp.c;h=0870420ced51f540d3bb672d6620ce62f65883fe;hb=87e738be5134dbd48e724075fab88589f3bf7f71;hp=aa6669d9f48cd780aa77be1ea996af89b361eba1;hpb=fcab496c12b2b94e85513c61513a24dbd9d6698a;p=libsigrok.git diff --git a/src/tcp.c b/src/tcp.c index aa6669d9..0870420c 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include +#include "config.h" /* TODO * Can we sort these include directives? Or do the platform specific @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -45,9 +44,23 @@ #include #endif +#if HAVE_POLL +#include +#elif HAVE_SELECT +#include +#endif + #include #include "libsigrok-internal.h" +/* + * Workaround because Windows cannot simply use established identifiers. + * https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown + */ +#if !defined SHUT_RDWR && defined SD_BOTH +# define SHUT_RDWR SD_BOTH +#endif + #define LOG_PREFIX "tcp" /** @@ -64,6 +77,7 @@ */ SR_PRIV gboolean sr_fd_is_readable(int fd) { +#if HAVE_POLL struct pollfd fds[1]; int ret; @@ -79,6 +93,26 @@ SR_PRIV gboolean sr_fd_is_readable(int fd) return FALSE; return TRUE; +#elif HAVE_SELECT + fd_set rfds; + struct timeval tv; + int ret; + + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + memset(&tv, 0, sizeof(tv)); + ret = select(fd + 1, &rfds, NULL, NULL, &tv); + if (ret < 0) + return FALSE; + if (!ret) + return FALSE; + if (!FD_ISSET(fd, rfds)) + return FALSE; + return TRUE; +#else + (void)fd; + return FALSE; +#endif } /**