slirp: use socket_set_nonblock

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main loop: use msec-based timeout in glib_select_fill

The timeval-based timeout is not needed until we actually invoke select,
so compute it only then.  Also group the two calls that modify the
timeout.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: disable fd_set-based glib integration under Win32

Using select with glib pollfds is wrong under Win32.  Restrict
the code to the POSIX case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: interrupt wait when data arrives on a socket

Right now, the main loop is not interrupted when data arrives on a
socket.  To fix this, register each socket to interrupt the main loop
with WSAEventSelect.

Since the interrupt is edge-triggered, we can activate it on all events
unconditionally.  If QEMU is momentarily uninterested on writability,
the main loop will not busy wait.  Instead, it may get one extra wakeup,
but then it will ignore the condition until qemu_set_fd_handler is called
to set an fd_write callback.  At this point the callback will be invoked,
with no wait since select() is tested before events the callback will
be invoked.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: replace WaitForMultipleObjects with g_poll

On Win32, glib implements g_poll using WaitForMultipleObjects
or MsgWaitForMultipleObjects.  This means that we can simplify
our code by switching to g_poll, and at the same time prepare for
adding back glib sources.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: integrate glib sources for Win32

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
clean up qemu_socket inclusions

Right now, slirp/slirp.h cannot include qemu_socket.h.  Clean this up,
and remove a duplicate prototype that was introduced because of that.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
use qemu_socket and qemu_accept consistently

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
prefer comparisons with zero

Compare return values with zero instead of directly with -1, so
that the code will work when returning negative errno values.

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

Also fix a couple of mismatches between close and closesocket.

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
introduce qemu_bind and qemu_connect

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
introduce qemu_getsockopt and qemu_setsockopt

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
return -errno from qemu_accept

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
return -errno from qemu_socket

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
return -errno from qemu_open and qemu_create_pidfile

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
return -errno from qemu_pipe and qemu_eventfd

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
use file descriptor to access sockets

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: drop the write callback

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