Greetings, and thanks Vadim!
Did a quick search and found this:
http://gcc.gnu.org/ml/libstdc++/2003-03/msg00304.html
=============================================================================
Following doesn't cause problems on mingw32 _unless_ we include winsock.h or
winsock2.h.
+#ifdef FIONREAD
+ // Pipes and sockets. + int __num = 0;
+ int __r = ioctl(this->fd(), FIONREAD, &__num);
+ if (!__r && __num >= 0)
+ return __num; +#endif
mingw does define FIONREAD (in winsock.h) but does not have ioctl.
It does have winsock versions: ioctlsocket (a barebones Berkeley ioctl)
and WSAIoctl which provides functionality similar to ioctl/fcntl.
To be functional these require a call to an initilizer function
WSAStartup, so we can't just #define ioctl ioctlsocket.
I could probably write a _glibcpp_ioctl() wrapper function and add it
as a an extra module to libgcc2 for mingw target.
=============================================================================
and this:
http://www.netperf.org/pipermail/netperf-talk/2007-February/000209.html
=============================================================================
+/*
+ * Sets a socket to non-blocking operation.
+ */
+int
+set_nonblock (SOCKET sock)
+{
+#ifdef WIN32
+ unsigned long flags = 1;
+ return (ioctlsocket(sock, FIONBIO, &flags) != SOCKET_ERROR);
+#else
+ return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
+#endif
+}
+=============================================================================
Linux does LISTEN_FOR_INPUT thusly:
#undef LISTEN_FOR_INPUT
#define LISTEN_FOR_INPUT(fp) \
do { int c = 0; \
if(((fp)->_IO_read_ptr >= (fp)->_IO_read_end) \
&& (ioctl((fp)->_fileno, FIONREAD, &c),c<=0)) \
return 0;} while (0)
Vadim, could you please try adding
/* How to check for input */
#undef LISTEN_FOR_INPUT
#define LISTEN_FOR_INPUT(fp) \
do { int c = 0; \
if(((fp)->_IO_read_ptr >= (fp)->_IO_read_end) \
&& (ioctlsocket((fp)->_fileno, FIONREAD, &c),c<=0)) \
return 0;} while (0)
to mingw.h? You may need to either include "winsock.h" and or
"winsock2.h" in file.d.
Thank you so much for your help here. If you know of a cross
compiling environment in which I can test these things under Linux, or
some remote mingw machine accessible via ssh, please let me know.
Take care,
=============================================================================
Camm Maguire writes:
Greetings, and thanks Vadim! Does this mean that non-blocking io via
fcntl does not work on mingw, or rather does it mean that the
configure test below is failing erroneously?
AC_MSG_CHECKING(check for listen using fcntl)
AC_TRY_COMPILE([#include <stdio.h>
#include <fcntl.h>
],
[FILE *fp=fopen("configure.in","r");
int orig;
orig = fcntl(fileno(fp), F_GETFL);
if (! (orig & O_NONBLOCK )) return 0;
],
[AC_DEFINE(LISTEN_USE_FCNTL)
AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no))
Yes, this test fails. Configure log attached.
With best regards,
Vadim
--
Vadim V. Zhytnikov
<address at hidden>
<address at hidden>
=============================================================================