[vlc-devel] [PATCH 1/3] poll: keep already signaled events that are not used between calls

Steve Lhomme robux4 at videolabs.io
Fri Nov 27 10:51:51 CET 2015


On Thu, Nov 26, 2015 at 5:57 PM, Steve Lhomme <robux4 at videolabs.io> wrote:
> ---
>  compat/poll.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/compat/poll.c b/compat/poll.c
> index fa94c93..0b2ae3e 100644
> --- a/compat/poll.c
> +++ b/compat/poll.c
> @@ -130,7 +130,6 @@ int poll(struct pollfd *fds, unsigned nfds, int timeout)
>      DWORD ret = WSA_WAIT_FAILED;
>      for (unsigned i = 0; i < nfds; i++)
>      {
> -        SOCKET fd = fds[i].fd;
>          long mask = FD_CLOSE;
>          fd_set rdset, wrset, exset;
>
> @@ -152,7 +151,8 @@ int poll(struct pollfd *fds, unsigned nfds, int timeout)
>          if (fds[i].events & POLLPRI)
>              mask |= FD_OOB;
>
> -        fds[i].revents = 0;
> +        /* discard the events we're looking for, keep the other ones */
> +        fds[i].revents ^= fds[i].events;

This change was inspired by this documentation:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms741572%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
"The socket's internal record of network events is copied to the
structure referenced by lpNetworkEvents, after which the internal
network events record is cleared."

Anytime we call WSAEnumNetworkEvents() the internal state is reset. So
if we only handle read events, and the next time write events, we may
have lost the fact that reading was available in the last call.

This is indeed the behaviour I see and why httpd wasn't going further
than a few read/write calls. After this line change, everything works
normally again, and we get the benefit of the alertable code.


>          evts[i] = WSACreateEvent();
>          if (evts[i] == WSA_INVALID_EVENT)
> --
> 2.6.3
>


More information about the vlc-devel mailing list