rewritten to be non-blocking: immediate write after connect may fail if the connection is not ready yet. Approved by: bdrewery (mentor)