[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] poll: fix regression in Win32 emulation of poll function
From: |
Daniel P. Berrange |
Subject: |
Re: [PATCH] poll: fix regression in Win32 emulation of poll function |
Date: |
Thu, 11 May 2017 14:20:55 +0100 |
User-agent: |
Mutt/1.8.0 (2017-02-23) |
On Thu, May 11, 2017 at 03:15:46PM +0200, Bruno Haible wrote:
> Hi Daniel,
>
> > it does not actually make poll() function correctly. We're still passing
> > HANDLE objects to the rpl_select() method, instead of calling
> > the native select() method.
>
> I don't agree with your reasoning. The select() calls in lib/poll.c:511 and
> lib/poll.c:547 is not passing a HANDLE, rather it passes bit masks of FDs
> that correspond to SOCKETs. Therefore I propose this patch:
Perhaps I'm mis-understanding, but I was looking at this code:
h = (HANDLE) _get_osfhandle (pfd[i].fd);
assure (h != NULL);
if (IsSocketHandle (h))
{
int requested = FD_CLOSE;
/* see above; socket handles are mapped onto select. */
if (sought & (POLLIN | POLLRDNORM))
{
requested |= FD_READ | FD_ACCEPT;
FD_SET ((SOCKET) h, &rfds);
}
if (sought & (POLLOUT | POLLWRNORM | POLLWRBAND))
{
requested |= FD_WRITE | FD_CONNECT;
FD_SET ((SOCKET) h, &wfds);
}
if (sought & (POLLPRI | POLLRDBAND))
{
requested |= FD_OOB;
FD_SET ((SOCKET) h, &xfds);
}
which takes the 'FD' and gets the associated SOCKET / HANDLE.
The 'xfds' fd_set is thus populated with a SOCKET, not a FD.
A few lines later we call select() with xfds.
The rpl_select() is expecting 'xfds' to be populated with
a FD, not a SOCKET / HANDLE.
> diff --git a/lib/poll.c b/lib/poll.c
> index c4b2127..2c6e879 100644
> --- a/lib/poll.c
> +++ b/lib/poll.c
> @@ -80,6 +80,14 @@
> first argument, not any possible gnulib override. */
> # undef recv
>
> +/* Here it does not matter whether we use the select() function from Windows,
> + that works only when all indicated FDs correspond to sockets and that
> + returns its error code in WSAGetLastError(), or the gnulib override that
> + does not have this limitation and that returns its error code in errno.
> + To simplify testing, use the lower-level Windows select() function
> + always. */
> +# undef select
> +
> static BOOL IsConsoleHandle (HANDLE h)
> {
> DWORD mode;
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|