AioContext: take bottom halves into account when computing aio_poll timeout

Right now, QEMU invokes aio_bh_poll before the "poll" phase
of aio_poll.  It is simpler to do it afterwards and skip the
"poll" phase altogether when the OS-dependent parts of AioContext
are invoked from GSource.  This way, AioContext behaves more
similarly when used as a GSource vs. when used as stand-alone.

As a start, take bottom halves into account when computing the
poll timeout.  If a bottom half is ready, do a non-blocking
poll.  As a side effect, this makes idle bottom halves work
with aio_poll, but that is not so important since they are
deprecated.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio-win32: Evaluate timers after handles

This is similar to what aio_poll does in the stand-alone case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio-win32: Factor out duplicate code into aio_dispatch_handlers

This will also be used directly for the GSource case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
AioContext: run bottom halves after polling

Make the dispatching phase the same before blocking and afterwards.
The next patch will make aio_dispatch public and use it directly
for the GSource case, instead of aio_poll.  aio_poll can then be
simplified heavily.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
AioContext: export and use aio_dispatch

Now, both aio_poll and the GSource use the same prepare/poll/dispatch
scheme, where prepare is aio_compute_timeout and dispatch is the
OS-dependent function aio_dispatch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
test-aio: test timers on Windows too

Use EventNotifier instead of a pipe, which makes it trivial to test
timers on Windows.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio-win32: add aio_set_dispatching optimization

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
AioContext: introduce aio_prepare

This will be used to implement socket polling on Windows.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio-win32: add support for sockets

Based on a patch from Or Goshen.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>