Doing a non-blocking `connect()` immediately followed by a `write()`
cause the `write()` to fail with `ENOTCONN` on FreeBSD.
This commit instead wait for the `connect()` operation to finish
using `poll()` with a short timeout if it returned `EINPROGRESS`,
so that either we have a connected socket to write to, or we fail.