[RFC/patch] New iteration at fixing 9533
Danny Smith
danny_r_smith_2001@yahoo.co.nz
Sun Mar 23 08:59:00 GMT 2003
--- Paolo Carlini <pcarlini@unitus.it> wrote: > Danny Smith wrote:
>
> >+#include <poll.h>
> >
> >and
> >
> >+ // Cheap test.
> >+ struct pollfd __pfd[1];
> >+ __pfd[0].fd = this->fd();
> >+ __pfd[0].events = POLLIN;
> >+ if (poll(__pfd, 1, 0) <= 0)
> >+ return 0;
> >
> >will break mingw32 (and possibly other targets) which doesn't have poll.h
> >or poll().
> >
> Ok, will add an autoconf test for it in the next iteration.
Thanks
>
> >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.
> >
> Therefore, it would be ok with you if I keep the ioctl() code which then
> will be actually enabled on mingw
> only after you contribute the wrapper?
>
Keep the ioctl code as is as far as mingw is concerned.
#define ioctl ioctlsocket would actually work with mingw as it turns out.
If the user code has not called WSAStartup previously then sockets aren't
enabled anyway. A call to ioctlsocket will return a failure code (!= 0)
and we just fall through to regular file case, which is the right thing to do.
The short answer is that your patch (with a guard for poll) works fine for
mingw.
> Consider that in the current library showmanyc() can only return zero in
> such cases for pipes, sockets and regular files.
Yes. I need to to construct some mingw testcases to satisfy myself at least.
>
> Thanks,
> Paolo.
>
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.
More information about the Libstdc++
mailing list