Fix errno references when handling socket errors.

When using socket functions, "sockerrno" is supposed to be used to
retrieve the error code as opposed to "errno", so that it is translated
to the correct call on Windows (WSAGetLastError() - Windows does not
update errno on socket errors). Unfortunately, the use of sockerrno is
inconsistent throughout the tinc codebase, as errno is often used
incorrectly on socket-related calls.

This commit fixes these oversights, which improves socket error
handling on Windows.
Protect against spurious connection events.

The event loop does not guarantee that spurious write I/O events do not
happen; in fact, they are guaranteed to happen on Windows when
event_flush_output() is called. Because handle_meta_io() does not check
for spurious events, a metaconnection socket might appear connected even
though it's not, and will fail immediately when sending the ID request.

This commit fixes this issue by making handle_meta_io() check the
connection status before assuming the socket is connected. It seems that
the only reliable way to do that is to try to call connect() again and
look at the error code, which will be EISCONN if the socket is
connected, or EALREADY if it's not.
Use Win32 events to interrupt the event loop from the TAP-Win32 thread.

Commit f9ab8e266b93aa3be772374ef4a8fdb06e376568 introduced a
event_flush_output() function that fires a write event on all IOs
registered for write. This was meant to expedite writes on TCP sockets
ordered from the TAP-Win32 thread; otherwise they would have to wait
until the select() call times out, at which point the event loop would
realize that there are new write I/Os to watch for.

The problem is, if the TCP socket is busy (blocked) when the TAP thread
calls route(), it will still wait for the event loop timeout instead of
waiting for the socket to become available.

This commit fixes the issue by registering all I/Os with a WSAEVENT
(which is really another name for a Win32 event) using WSAEventSelect().
Instead of using select() to wait for events, we now use
WSAWaitForMultipleEvents(), but only for notification - select() is
still used to find out which sockets actually fired so that we can
keep as much common code as possible.

This new waiting method is equivalent to just using select(), but with
one added feature: by manually signaling the WSAEVENT object, the
WSAWaitForMultipleEvents() can be manually interrupted from any thread.
Thus, the TAP-Win32 thread can now cleanly and efficiently request for
an event loop restart simply by signalling the event.