# Check for compiler support of 128 bit integers
AC_CHECK_TYPES([__int128_t, __uint128_t], [], [], [])
+AC_CACHE_CHECK([for poll], [sr_cv_have_poll],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <poll.h>]],
+ [[(void) poll(0, 0, -1);]])],
+ [sr_cv_have_poll=yes], [sr_cv_have_poll=no])])
+AS_IF([test "x$sr_cv_have_poll" = xyes],
+ [AC_DEFINE([HAVE_POLL], [1],
+ [Specifies whether we have the poll(2) function.])])
+AC_CACHE_CHECK([for select], [sr_cv_have_select],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
+ [[(void) select(0, 0, 0, 0, 0);]])],
+ [sr_cv_have_select=yes], [sr_cv_have_select=no])])
+AS_IF([test "x$sr_cv_have_select" = xyes],
+ [AC_DEFINE([HAVE_SELECT], [1],
+ [Specifies whether we have the select(2) function.])])
#######################
## miniLZO related ##
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
+#include "config.h"
/* TODO
* Can we sort these include directives? Or do the platform specific
#include <errno.h>
#include <glib.h>
-#include <poll.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#endif
+#if HAVE_POLL
+#include <poll.h>
+#elif HAVE_SELECT
+#include <sys/select.h>
+#endif
+
#include <libsigrok/libsigrok.h>
#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"
/**
*/
SR_PRIV gboolean sr_fd_is_readable(int fd)
{
+#if HAVE_POLL
struct pollfd fds[1];
int ret;
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
}
/**